[Haskell-cafe] Re: monad subexpressions

Stefan O'Rear stefanor at cox.net
Fri Aug 3 20:51:55 EDT 2007


On Fri, Aug 03, 2007 at 05:48:18PM -0700, Brandon Michael Moore wrote:
> General purpose brackets are overkill here. I would really like a simple
> monadic case. What's so bad about
> 
> caseM mexpr of
>   p1 -> branch1
>   p2 -> branch2
> 
> vvvv
> 
> (mexpr >>= \e -> case e of
>   p1 -> branch1
>   p2 -> branch2)
> 
> It's simple sugar for working with monadic code, much like do notation.
> (indeed, it seems to plug a gap - we have do for sequencing, liftM and
> so on for application, but no sugar for case discrimination)
> 
> It's a much simpler sort of thing than this fancy sugar for intermixing
> code in various monads people have been talking about (so far it seems
> assumed that one is just Identity...)

I think the CaseLambda proposal on the Haskell' wiki solves this one
nicely.

mexpr >>= case of
  p1 -> branch1
  p2 -> branch2

You still have to use >>=, but you don't have to name the scrutinee (and
names are expensive cognitively).

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070803/c6bddc1c/attachment.bin


More information about the Haskell-Cafe mailing list