Existentials for multi-parameter type classes?

Hi folks, I know how to write existentially quantified data constructors for single-parameter type classes, but I'm having trouble doing it for multi-parameter type classes. Is it not possible, or am I just using the wrong syntax? I have this class: class Collidable a b where collideWith :: a -> b -> String And I tried to define an existentially quantified data constructor thusly: data Collision = forall a. (forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b}) I get a parse error. So then I tried: data Collision = forall a. forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b} I get a different parse error. Is there any way to make this work? Thanks, Lyle

I highly recommend writing all existentials using GADT syntax. It is *far*
more intuitive.
David
On Mar 20, 2015 1:12 AM, "Lyle Kopnicky"
Hi folks,
I know how to write existentially quantified data constructors for single-parameter type classes, but I'm having trouble doing it for multi-parameter type classes. Is it not possible, or am I just using the wrong syntax?
I have this class:
class Collidable a b where collideWith :: a -> b -> String
And I tried to define an existentially quantified data constructor thusly:
data Collision = forall a. (forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b})
I get a parse error. So then I tried:
data Collision = forall a. forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b}
I get a different parse error. Is there any way to make this work?
Thanks, Lyle
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

There is!
data Collision = forall a b. Collidable a b => Collision {collider1 ::
a, collider2 :: b}
On Thu, Mar 19, 2015 at 10:11 PM, Lyle Kopnicky
Hi folks,
I know how to write existentially quantified data constructors for single-parameter type classes, but I'm having trouble doing it for multi-parameter type classes. Is it not possible, or am I just using the wrong syntax?
I have this class:
class Collidable a b where collideWith :: a -> b -> String
And I tried to define an existentially quantified data constructor thusly:
data Collision = forall a. (forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b})
I get a parse error. So then I tried:
data Collision = forall a. forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b}
I get a different parse error. Is there any way to make this work?
Thanks, Lyle
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

And in GADT syntax with crazy records, that's
data Collision where
Collision :: Collidable a b => {collider1 :: a, collider2 :: b} ->
Collision
Or (much cleaner) without the crazy record syntax,
data Collision where
Collision :: Collidable a b => a -> b -> Collision
On Mar 20, 2015 1:15 AM, "Michael Sloan"
There is!
data Collision = forall a b. Collidable a b => Collision {collider1 :: a, collider2 :: b}
Hi folks,
I know how to write existentially quantified data constructors for single-parameter type classes, but I'm having trouble doing it for multi-parameter type classes. Is it not possible, or am I just using the wrong syntax?
I have this class:
class Collidable a b where collideWith :: a -> b -> String
And I tried to define an existentially quantified data constructor
On Thu, Mar 19, 2015 at 10:11 PM, Lyle Kopnicky
wrote: thusly: data Collision = forall a. (forall b. Collidable a b => Collision
{collider1
:: a, collider2 :: b})
I get a parse error. So then I tried:
data Collision = forall a. forall b. Collidable a b => Collision {collider1 :: a, collider2 :: b}
I get a different parse error. Is there any way to make this work?
Thanks, Lyle
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (3)
-
David Feuer
-
Lyle Kopnicky
-
Michael Sloan