[Haskell-cafe] Why no IO transformer monad?

Keean Schupke k.schupke at imperial.ac.uk
Mon Dec 20 08:19:55 EST 2004


Perhaps you would care to explain this then?

   

    class Runnable m n where
       run :: m -> n

    class (Monad m,Monad (t m)) => MonadT t m where
       up :: m a -> t m a
       down :: t m a -> m a

    instance (Monad m,MonadT t m,Monad (t m)) => Runnable (t m a) (m a) 
where
        run = down

Or perhaps look at the type of the state transformer monad:

    newtype StateT st m a = ST { runST :: st -> m (st,a) }

To me it is quite clear that the return type runST returns "m (st,a)"
where m is the _base_ monad so lifting IO through the state-transformer 
gives:

    StateT st IO a

and applying runST to this type gives: IO (st a)...

    Keean.


Udo Stenzel wrote:

>Keean Schupke <k.schupke at imperial.ac.uk> schrieb am 20.12.04 12:13:08:
>  
>
>>I thought you would get the following if you have a transformer 'M':
>>   
>>    runM :: M IO a -> IO a
>>    
>>
>
>That's what I thought, too.  But it's the other way 'round. 
>Well, I can't comment on _why_ it's so counter-intuitive, but I'm pretty
>sure, the outermost transformer appears innermost in the final type.  
>It all makes sense somehow, you just have to remember that
>transformer types are somehow written backwards.
>
>
>Udo.
>__________________________________________________________
>Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
>weltweit telefonieren! http://freephone.web.de/?mc=021201
>
>  
>



More information about the Haskell-Cafe mailing list