[Haskell-cafe] Polymorphic (typeclass) values in a list?

Jules Bean jules at jellybean.co.uk
Fri Oct 19 12:37:54 EDT 2007


Sebastian Sylvan wrote:
> On 19/10/2007, Kalman Noel <kalman.noel at bluebottle.com> wrote:
>>    data ExistsNumber = forall a. Num a => Number a
> 
> I'm without a Haskell compiler, but shouldn't that be "exists a."?
> IIRC forall will work too, but the "right" way to do it is "exists",
> right?

No. It's been suggested but that's not how GHC or Hugs existentials work.

The syntax isn't actually illogical, it's just very confusing. What (by 
convention) you are actually doing here is you are annotating the type 
of the constructor. So you are saying that the constructor 'Number' has 
the type "forall a . Num a => a -> ExistsNumber".

This is perfectly correct, but it is confusing that what you are doing 
is annotating the *constructor* and not the data-type itself, per se, 
although it doesn't much look like it.

This looks very very much clearer in GADT syntax, since in GADT syntax 
you always give constructors explicit types:

type ExistsNumber where
    Number :: forall a . Num a => ExistsNumber a


Jules


More information about the Haskell-Cafe mailing list