Here's two implementations of a binary search tree in OCaml and Rust. The Rust version was written to
deliberately look as close to the OCaml as possible (and it'd get pretty close if I used match
instead of OCaml's variants). I'm pretty sure my OCaml implementation is idiomatic, and I'd like some advice on
what steps I'd probably take to make the Rust example more idiomatic. My objective is to talk about how
close the examples can be to each other as well as how different the examples can be (hopefully demonstrating
strengths for both.)
Any other thoughts or ideas are also helpful and super appreciated!
Ah!!! That impl refactor is totally what I'm looking for! I really wasn't happy with creating that tree when compared to OCaml's Pipe operator, but that refactor is totally where it's at! Thank you so much! I'd love to see what Jake thinks as well!
I'm really enjoying where the comparing and contrasting of a simple problem is evolving. I may do another small comparison problem, but I'm also thinking about easy changes that people to add some interaction to help people feel good about what they're learning. I want to be very careful not to "blow anyone's mind" because I want people to leave feeling empowered to experiment and enthusiastic. Do you have any thoughts on that?
The
'a
in OCaml indicates a generic type. I can pass anything that OCaml knows how to compare (comes from the Pervasives module I think?) Rust is able to just start handling it by implementing PartialOrd on the struct. I actually prefer how Rust operates here; my research doesn't lead me to an obvious way to extend/add Pervasives for a more complex type (granted I could have easily just missed it), but it's pretty obvious what my structs need to provide in Rust. I like it!