3 ms·
What features does SML or OCaml's type system have that Rust's doesn't? Haskell has higher-kinded type parameters and Idris has dependent types. But SML and OC
by pcwalton 11y ago
What features does SML or OCaml's type system have that Rust's doesn't?
Haskell has higher-kinded type parameters and Idris has dependent types. But SML and OCaml don't even have typeclasses at all, much less higher kinds.
Furthermore, what makes Rust's type system interesting isn't just its use of regions (which the ML Kit used); it's regions combined with inherited mutability plus the borrow check to maintain soundness.
- cm3 11y agoOCaml's module system is a nice tool for many cases that is only slowly getting into Haskell via Backpack but not there yet. So that's one. GHC 8.0 almost has dependent types and the expectation is feature completeness in 8.2, thought what's in 8.0 is already useful. I like and use Rust and the design decisions that led to a very capable region system that allows one to write data race free and memory correct code is excellent. Haskell doesn't have such a thing because it doesn't try avoid GC. I didn't do a point by point comparison of Rust expressiveness vs Haskell recently, but I don't remember it being close. Rafael might need to write a Rust for for Haskellers as an update of his "for OCamlers" post a while back.
- knz42 11y agoThe post is called "Rust for functional programmers" and contains side-by-side comparisons with both OCaml and Haskell. http://science.raphael.poss.name/rust-for-functional-programmers.html http://science.raphael.poss.name/rust-for-functional-program... you might be confusing it with the other post "Haskell for OCaml programmers"? It is a bit outdated but as far as I can see not inaccurate yet. I only plan to update it when HKTs make it to Rust.
- skorgu 11y agoHey, that's a really useful reference, thanks. I actually learned something about OCaml from it!
- LeonidasXIV 11y ago> But SML and OCaml don't even have typeclasses at all, much less higher kinds. There is a fun library[0] with a pretty good paper[1] on how to do that in OCaml :-) [0]: https://github.com/ocamllabs/higher https://github.com/ocamllabs/higher [1]: https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf https://ocamllabs.github.io/higher/lightweight-higher-kinded...
- cwzwarich 11y agoOCaml has higher-kinded types in the guise of modules, and so does SML with common extensions. I'm not completely sure what you're implying, but type classes aren't required for higher kinds. OCaml has a powerful module system, labeled and optional function parameters, row polymorphism, equirecursive types, and GADTs. Most of these features would be fairly difficult to add to Rust. OCaml also has a better track record with soundness issues than Rust, and more interesting fragments of the language have been formalized.
- mkehrt 11y agoIn MLs, you can often replace what would be a typeclass in haskell with idiomatic uses of functors (parameterized modules). It gets kind of hairy if you do it a lot, though.
- deleted 11y ago[deleted]