[Haskell-cafe] Parameterized monad transformers

Miran Lipovača miran.lipovaca at gmail.com
Sun Feb 15 19:37:40 EST 2009

Howdy y'all!

I was reading sigfpe's Beyond Monads post 
(http://blog.sigfpe.com/2009/02/beyond-monads.html) about parameterized monads. 
Great post, makes you go: this is so elegant and simple, why didn't I think of that?

Anyway, I was wondering whether those monads have corresponding transformers, and 
if so, what they look like and what they are good for? Is there any weight to the 
idea at all?

I don't know much about monad transformer theory, but I do imagine that for 
transformers to be useful, they have to be stackable, so the underlying monad of a 
parameterized monad also has to be a parameterized monad. I asked around in 
#haskell and ski_ and I had a couple of ideas exploring the concept (although he 
did most of the exploring, I just carried his luggage).

Seeing how parameterized monads are gotten by just loosening some restrictions on 
normal ones and drawing then parallels between them, I think the same methodology 
could be applied to transformers.

So there should be a transformer version t of a parameterized monad m and a 
lifting operation plift that lifts m to t. At first I did what sigfpe did with 
non-transformer monads, which was to just implement the appropriate functions for 
the more general monads and see what GHCI tells us about the type. I first thought 
about having a parameterized StateT, PStateT:

newtype PStateT m s1 s2 a = PStateT { runPStateT :: s1 -> m (a, s2) }

along with a lifting operation

plift :: (PMonad m) => m s1 s2 a -> t (m s1 s2) s3 s3 a

but I don't think that's cool because of the different kind of the underlying 
monad. So then ski_ suggested

newtype PStateT m (s1,s1') (s2,s2') a = PStateT { runPStateT :: s1 -> m s1' s2' 
(Pair a s2) }

where (s1,s1') and (s2,s2') stand for the pair of types and not a (,) type 
constructor with two types applied as type parameters. That's why the pair in the 
result is represented as Pair a s2. Anyway, s1' and s2' represent the category 
tail and head of the underlying parameterized monad. With that, the lifting 
operation would have a type of

plift :: (PMonad pm) => pm s1 s2 a -> t pm (s, s1) (s, s2) a

basically I'm just wondering how you guys think the transformer versions of 
parameterized monads work and what their types should be. And if you think they're 
feasible at all. So basically just talk about parameterized monad transformers here :]


More information about the Haskell-Cafe mailing list