[Haskell-cafe] Existentially-quantified constructors, Eq and Show

John Meacham john at repetae.net
Wed Dec 7 19:09:31 EST 2005


On Wed, Dec 07, 2005 at 10:12:07PM +0000, Joel Reymont wrote:
> data State a
>     = Start
>     | Stop
>     | (Show a, Eq a) => State a

you arn't using existential types here. an example with an existential
type would be (in ghc syntax)

> data forall a . State
>     = Start
>     | Stop
>     | (Show a, Eq a) => State a

note that what makes it existential is that 'a' does not appear as an
argument to State, but rather is bound by the 'forall'.
so if the above is what you want, then I believe you have the shortest
way but you can add some rules to DrIFT if you want to do so
automatically.

if you are okay with a being an argument then

> data State a
>     = Start
>     | Stop
>     | State a
>    deriving(Show,Eq)

will do what you want I believe.

        John

PS. many, including me, feel 'forall' is a misnomer there and should be
the keyword 'exists' instead. so just read 'foralls' that come _before_
the type name as 'exists' in your head and it will make more sense.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell-Cafe mailing list