Existentially quantified types example fails in ghc 7.2.2

858 views Asked by At

According to Wikipedia, the following code should compile,

{-# LANGUAGE RankNTypes #-}
data T = MkT (exists a. Show a => a)

But, I'm not having any luck. ghci 7.2.2 complains with,

test.hs:2:23:
    Illegal symbol '.' in type
    Perhaps you intended -XRankNTypes or similar flag
    to enable explicit-forall syntax: forall <tvs>. <type>
Failed, modules loaded: none.

The original link is here: http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types

Thanks in advance!

2

There are 2 answers

3
Tikhon Jelvis On

The page you linked mentions that exists as a keyword doesn't exist but that you can get the same behavior using forall. Note that your particular example is captioned "(psuedo) haskell".

They say it would be equivalent to:

data T = forall a. MkT a

with

MkT :: forall a. a -> T
0
Ping Jia On

in ghci mode, it should be like this.

ghci> :set -XRankNTypes