4 ms·
> I’d wager that you have a better chance of translating OCaml or non-fancy Haskell straight into Rust than you do C++. I found that translating OCaml code to
by gnuvince 6y ago
> I’d wager that you have a better chance of translating OCaml or non-fancy Haskell straight into Rust than you do C++.
I found that translating OCaml code to Rust is frustrating, because you cannot easily and cheaply replicate the functional approach. It's much more Rustic to take an object by mutable reference and modify it in-situ than it is to take an immutable reference and return a new object. The reason is that in OCaml, you have structural sharing, i.e., multiple pointers pointing into the same data structure, which is a big no-no in Rust, so if you want to replicate the functional OCaml code, you begin allocating a new, complete data structure every time, and that's costly.
- nilkn 6y agoWell, of course. Rust is not designed around immutable data structures. There are going to be differences because it's simply not the same language. This [0] example, written by a notable Haskeller, illustrates what I mean pretty well and also touches on what you just pointed out. It's also very consistent with my own experience. [0]: https://donsbot.wordpress.com/2020/07/04/back-to-old-tricks-or-baby-steps-in-rust/ https://donsbot.wordpress.com/2020/07/04/back-to-old-tricks-...