Parameterising Class Constraints in Existential Types

Simon Peyton-Jones simonpj@microsoft.com
Thu, 29 Mar 2001 23:57:16 -0800


It seems reasonable to me, and GHC is happy.=20
Here's a working example:

Simon


class MyClass a b where
	foo :: a -> b -> Int

data Special =3D forall b. (MyClass Int b)=3D> MkSpecial b
data General a =3D forall b. (MyClass a b)=3D> MkGeneral b

instance MyClass Int Bool where
   foo x False =3D -x
   foo x True  =3D x

xs :: [General Int]
xs =3D [MkGeneral True, MkGeneral False]

main =3D print [foo (3::Int) x | MkGeneral x <- xs]



| -----Original Message-----
| From: Ashley Yakeley [mailto:ashley@semantic.org]
| Sent: 29 March 2001 10:47
| To: Haskell List
| Subject: Parameterising Class Constraints in Existential Types
|=20
|=20
| Is this valid (extended) Haskell?
|=20
| --
| class MyClass a b where
| 	foo :: a -> b -> Int
|=20
| data Special =3D forall b. (MyClass Int b)=3D> MkSpecial b
| data General a =3D forall b. (MyClass a b)=3D> MkGeneral b
| --
|=20
| Hugs complains about the 'General' line but has no problem with the=20
| 'Special' line...
|=20
| --=20
| Ashley Yakeley, Seattle WA
|=20
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell
|=20