|
|
|
|
|
by Tarean
3400 days ago
|
|
The implied bound one reminded me of a very similar thing in haskell https://prime.haskell.org/wiki/NoDatatypeContexts . Basically data Hashable a => Set a = ...
is completely useless. It only forces you to add constraints to functions that, if necessary, would be required anyway.Not to be confused with existential quantification data ExistentialSet a = forall a . Hashable a => ...
which carries a reference to the hash function in the instances, similar to trait objects in rust. |
|
Haskell hasn't found DatatypeContexts very useful, but Rust has. In my opinion this is largely because of the difference in what our type systems mean - in Rust, types carry a lot more information about the memory model & data layout than in Haskell. This has led to a different skew.
In Haskell, DatatypeContexts also create struggles with higher kinded polymorphism (you can't implement Functor for the definition of Set you just provided, for example), but in Rust, the same memory model concerns that make datatype constraints useful make traits like Functor less useful.