[Haskell-cafe] Re: monad subexpressions

Claus Reinke claus.reinke at talk21.com
Fri Aug 3 09:12:26 EDT 2007

> can you please rewrite *p++=*q++ in haskell?

assuming these operations

    i :: V a -> IO (V a)   -- incr var addr, return old addr
    r  :: V a -> IO a       -- read var
    w  :: V a -> a -> IO () -- write var value

and this unfolded translation

    do { qv <- r q; w p qv; i p; i q }

assuming further these liftings

    ap1 :: (a->m b) -> (m a->m b)
    ap2 :: (a->b->m c) -> (m a->m b->m c)

then we can define

    (=:) :: IO (V a) -> IO a -> IO ()
    mv =: ma = (ap2 w) mv ma

and get this inlined version

      i p =: (r `ap1` i q)

but one might still prefer

    do { w p =<< r q; i p; i q }

but whatever line-noise one prefers, this still seems a call for
better combinators in the standard libs, rather than a call for
more syntax.


More information about the Haskell-Cafe mailing list