by myst · 9y ago · 0 comments
Trait objects are basically existential types, with a few more restrictions on them. But in essence polymorphism in Haskell and Rust are very similar.
The big thing Rust is missing is higher kinded polymorphism, ie the ability to abstract over type constructors. This makes it easy, for example, to abstract over a container type while putting different things in that container.
This has get approved in the Associated Type Constructors RFC, but it's still in the works for actually landing.
Whilst this is obviously useful, it makes it impossible to perform parametricity type-based reasonbig.
http://science.raphael.poss.name/rust-for-functional-program...
Although Rust heavily borrows from the ML family, the fact it has mutability and imperative reasoning makes it hard to compare them.
But if you want a short one:
- Sum Types EDIT: AND Product Types (silly me)
- function-objects & closures
- typeclasses (as far as I can tell), but no higher kinded types
- no monads, functors nor monoids built-in
- trait objects (eg. runtime polymorphism, think "abstract classes")
I don't think Rust is that much different from other functional languages. The main critical difference is the manual memory management feature - the way it's acknowledged and used throughout the language and the ecosystem means that the functional patterns commonly used in garbage collected languages don't look nearly as natural in Rust.
Maybe I'm missing something, but aren't tuples and structs/records examples of product types? Which both rust and haskell have?
Rust most certainly has them, as does Haskell. Records/structs of course are just the same thing with names for the components.
Thus, even Java has product types.
Even C has product types. Which is why I'm always bothered when people claim language X lacks algebraic data types.
They probably lack sum types, but are very unlikely to lack product types.
{ 1 = "hi", 2 = "howdy" };
And get: val it = ("hi","howdy") : string * string