
On 9/14/07, Jules Bean
{-# 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