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

Sebastian Sylvan sebastian.sylvan at gmail.com
Fri Oct 19 12:11:04 EDT 2007

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",
So to avoid confusion, use "exists" rather than "forall" when you want
existential rather than universal quantification.

Also, you might want to instantiate the existential type in the class too. E.g.
class Render a where
   render :: a -> IO ()

instance Render ... where -- lots of these

data Renderable = exists a . Render a => Renderable a

instance Render Renderable where
   render (Renderable a) = render a

Now we can call "render" on both the actual renderable values
themselves, as well as well as the "wrapped" ones.

Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list