[Haskell] Rank-N types vs existential types

Andre Pang ozone at algorithm.com.au
Wed Apr 27 07:16:16 EDT 2005

Hi all,

Let's say I have the following two data types:

> {-# OPTIONS_GHC -fglasgow-exts #-}
> module RankNVsExists where
> data RankN  = RankNEq (forall a. Eq a => a -> a -> Bool)
>             | RankNOrd (forall a. Ord a => a -> a -> Bool)
> data Exists = forall a. Eq a => ExistsEq (a -> a -> Bool)
>             | forall a. Ord a => ExistsOrd (a -> a -> Bool)

So, the RankN type uses rank-2 polymorphism to "hide" the expression 
inside the type, whereas the Exists type uses existentially quantified 
types instead.  The two seem pretty equivalent to me, since the data 
constructors have the same type.  However, I can't help but feel that 
I'm missing something fundamental about a difference between them.  Are 
the two completely isomorphic?  Is there some advantage or disadvantage 
to using one over the other?

% Andre Pang : trust.in.love.to.save  <http://www.algorithm.com.au/>

More information about the Haskell mailing list