[Haskell-cafe] Lifting monad syntax sugar

Maciej Piechotka uzytkownik2 at gmail.com
Thu Dec 31 11:01:27 EST 2009


I'm not quite sure if it exists but with working with lifted
monads/lifted arrows it would be useful.

Let f be function from m a to n a where m and n are monad (arrows
respectivly) for any a then:

> do v <- something 0
>    lift (f) g <- somethingElse
>             h <- somethingInLift
>             i <- somethingCompletlyDifferent v
>    doSomething g h

is syntaxt sugar of

> do v <- something 0
>    (g, h) <- f $ do g <- somethingElse
>                     h <- something 
>                     i <- somethingCompletlyDifferent v
>                     return (g, h)
>    doSomething g h

and

> proc (x) -> do v <- something -< x
>                lift (f) g <- somethingElse -< ()
>                         h <- somethingInLift -< ()
>                         i <- doSomething -< v
>                somethingCompletlyDifferent -< (g, h)

is syntax sugar of

> proc (x) -> do v <- something -< g
>                (g, h) <- f (proc (v) -> do g <- somethingElse -< ()
>                                            h <- somethingInLift -< ()
>                                            i <- doSomething -< v
>                                            returnA -< (g, h)) -< v
>                somethingCompletlyDifferent -< (g, h)

I am aware that syntatic sugar is evil
(http://www.haskell.org/haskellwiki/Syntactic_sugar/Cons) and therefore
I'd prefere to post it here before submitting feature request to ghc
(I'll also threat no resoponses as nobody care so why pollute syntax).

Regards
PS. I'm aware that lift is existing function (Control.Monad.Trans) so
possibly other name will be choosen.
PPS. Syntax is similar to rec as last line can be binding




More information about the Haskell-Cafe mailing list