Haskell supports type classes, like equality:
class Eq a where
(==) :: a -> a -> Bool
Rust does the same with type traits:
pub trait Draw {
fn draw(&self);
}
Now, it's possible to declare in Haskell a list whose elements must belong to the equality type class: Eq a => [a] (I believe a is called a constrained type in Haskell). However, the elements of the list still must all be the same type! Say, all Integer or all Float or something. In Rust, however, one can have a list (a vector) of values where each implements a given trait but they are not necessarily the same concrete type: Vec<Box<dyn Draw>>. Is there a way to do the same in Haskell? Like, I want a list of values but all I care about is that each belong to some type class but not necessarily the same concrete type.
dyntrait objects in Rust fairly frequently, and I almost never use existentials in Haskell. It's just a difference in the way the language nudges you and the way you solve problems in different languages.Eq(I don't know how Rust does equality checks), having a list of objects of different types that all implementEqwould be entirely useless. That's because(==) :: a -> a -> Boolrequires two objects known to be of the same type for the call to even typecheck. Only an interface that can do interesting things with a single object makes much sense to use with this capability.data ExContainer where EC :: Num a => IntMap a -> ExContainerseems like it could plausibly use binary operators like(+)and(*)(or even(==)if you addedEq) nontrivially, even though theais existentially quantified.IntMapof some unknownathat implementsNum, and one could argue that that is an example of an interface that lets you do interesting things with a single value (being theIntMap aas a whole, which of course can containmultipleas). A list of yourExContainer, as the OP was thinking about, would have every element in the list need to contain anIntMap(just for varyinga), and you couldn't use the instances across values from the two different maps.