[Haskell-cafe] Re: monad subexpressions

apfelmus apfelmus at quantentunnel.de
Fri Aug 3 04:05:22 EDT 2007

Chris Smith wrote:
> I've heard Simon (Peyton-Jones) twice now mention the desire to be able 
> to embed a monadic subexpression into a monad.  That would be 
> http://article.gmane.org/gmane.comp.lang.haskell.prime/2267 and in the 
> recent OSCON video.

I still think that this syntax extension has profound impact and is a
bad idea. Simon's and Neill's use case was the dreaded name-supply monad
where the order of effects really doesn't matter up to alpha-conversion.
The objection to that use case is that monads are not the right
abstraction for that, they're too general. Also, a workaround is to lift

  f :: a -> b -> m c
  g :: d -> m b


  f' :: m a -> m b -> m c
  g' :: m d -> m b

and thus flip the need for argument sugar

  f $(g x) y   VS   f' (g' (r$ x)) (r$ y)

With r = return, the latter is Haskell98. See also


> Also, I got so frustrated that I ended up abandoning some code
> recently because STM is, in the end, so darn hard to use as a
> result of this issue. I'd love to see this solved, and I'm quite
> eager to do it.

This sounds suspicious, since the order of effects is of course
important in the STM monad. Can you post an example of code you intend
to abandon due to ugliness? I'd be astonished if there's no better way
to write it.


More information about the Haskell-Cafe mailing list