[Haskell-cafe] Rank-2 types in classes

Yves Parès limestrael at gmail.com
Wed Mar 2 10:11:47 CET 2011


I'm working on a library which aims to be a generic interface for 2D
rendering. To do that, one of my goals is to enable each implementation of
this interface to run in its own monad (most of the time an overlay to IO),
thus giving me the following class

class (Monad (IM i x)) => Impl i x where
    data IM i x :: * -> *

(where IM means Implementation Monad)

Here, 'x' aims at being a phantom type that ensures a type safe context for
some operations.
E.g., operations that need to occur in a window will have the type:
   IM i Window a
And will be run by the function:
   withinWindow :: Window -> IM i Window a -> IM i x a

This makes an operation that doesn't instantiate 'x' context-independent.

My problem, then, is that in the definition of class Impl the type variable
'x' is useless, since every implementation must leave uninstantiated.

I would like to write something like :

class (forall x. Monad (IM i x)) => Impl i where
    data IM i :: * -> * -> *

But GHC forbids me to do so.

Any suggestion would be warmly welcomed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110302/966a8fc9/attachment.htm>

More information about the Haskell-Cafe mailing list