4 ms·
existential types allow you to make it dynamic. see https://wiki.haskell.org/Existential_type https://wiki.haskell.org/Existential_type, there's a section compa
by uryga 7y ago
existential types allow you to make it dynamic. see https://wiki.haskell.org/Existential_type https://wiki.haskell.org/Existential_type, there's a section comparing it to OOP-style dynamic dispatch
simple example copied from the linked article:
data Obj = forall a. (Show a) => Obj a
xs :: [Obj]
xs = [Obj 1, Obj "foo", Obj 'c']
doShow :: [Obj] -> String
doShow [] = ""
doShow ((Obj x):xs) = show x ++ doShow xs
we can have a "heterogenous" list of `Obj`s, like a java `ArrayList<IPrintable>`. each `Obj` is basically a pointer to the actual value of some type T and a pointer to T's Show dictionary (vtable). Which is afaik analogous to how OOP languages do it