[Haskell-cafe] MonadGL - Partitioning effects without giving up type inference

Stuart Cook scook0 at gmail.com
Thu Sep 13 21:29:27 EDT 2007


On 9/14/07, Jules Bean <jules at jellybean.co.uk> wrote:
>  > {-# OPTIONS -fglasgow-exts #-}
>
> (extensions are only for deriving (Monad), it's not important)

If that's the case, you should be able to write (assuming GHC 6.6+)

  {-# LANGUAGE GeneralizedNewtypeDeriving #-}

though I don't know how well other implementations support it.


> Incidentally, I don't believe this technique has any performance
> implication at all. The newtypes are all erased at compile time.

One potential slowdown is the added typeclass polymorphism (for
MonadGL); hopefully the compiler is clever enough to eliminate
dictionary passing/lookup.


> Any comments? I'm sure this has been shown before but I don't
> remember where.

I'm not aware of any GL-specific explanation, but I think the trick of
using monad classes as a capability system has been around for a
while. (In the "folklore", you might say.)

Using classes for transparent lifting seems to come up in discussions
of the standard library's I/O functions. Writing "liftIO" everywhere
is just as painful as "runGL".


Stuart


More information about the Haskell-Cafe mailing list