Existential Datatypes

Jeremy Shaw jeremy.shaw@lindows.com
Sun, 30 Jun 2002 12:27:12 -0700


Hello,

I have a question regarding named fields and existential data types.

I want to extend this example from the User's guide to use named fields:

data Foo = forall a. MkFoo a  (a->Bool)
	 | Nil

foo = MkFoo 'g' isUpper

I tried:

data Foo2 = forall a. MkFoo2 { val2 :: a
			     , func2 :: a -> Bool
			     }

But the compiler said:

    Can't combine named fields with locally-quantified type variables
    In the declaration of data constructor MkFoo2
    In the data type declaration for `Foo2'

Then I tried:

data Foo3 = MkFoo3 { val3 :: forall a. a
		   , func3 :: forall a. (a -> Bool)
		   }


foo3 = MkFoo3 'g' isUpper

And the compiler said:

    Inferred type is less polymorphic than expected
        Quantified type variable `a' is unified with `Char'
    Signature type:     forall a. a
    Type to generalise: Char
    When checking an expression type signature
    In the first argument of `MkFoo3', namely 'g'
    In the definition of `foo3': MkFoo3 'g' isUpper


Am I doing something wrong, or can GHC just not do what I want yet?
>From what I gathered looking through the mailing list, existential
types are still a bit hacked up?

Thanks!

Jeremy Shaw.