Even without extension ExistentialQuantification
, Haskell supports some existential types, via the type isomorphism, for any typeclass C
,
(forall a. C a => (a -> b)) ~ ((exists a. C a => a) -> b)
So a function f :: C a => a -> b
expects an argument x
of type exists a. C a
. But Haskell doesn't allow to pattern match x
against some types of C
(finishing by a wild match _
, because type classes are usually infinite).
This is strange, because existential types are generalized sum types. Haskell does support finite sum types with the data
keyword and allows pattern matching for them. In languages such as C++, Java and C#, existential types are interfaces and they support pattern matching with keywords such as dynamic_cast
or instanceof
.
Is there a reason why Haskell didn't implement pattern matching for functions such as f
above ?
Typeable
. – kosmikus(forall a. (C a => a) -> b) ~ ((exists a. C a => a) -> b)
? – gallais