[Haskell-cafe] ANN: exists-0.1

Tillmann Rendel rendel at informatik.uni-marburg.de
Mon Feb 6 17:07:13 CET 2012


Gábor Lehel wrote:
> data E = forall a. C a => E a
> I don't know if anyone's ever set out what the precise requirements
> are for a type class method to be useful with existentials.

More than you seem to think. For example:

   data Number = forall a . Num a => Number a

   foo :: Number -> Number
   foo (Number x) = Number (x * x + 3)

So the binary operation (*) can be used.

Note that from a type-checking perspective, the pattern match on (Number 
x) also extracts the type, which is then available when checking the 
right-hand side.


More information about the Haskell-Cafe mailing list