[Haskell-cafe] Re: Lambda-case / lambda-if

Nicolas Pouillard nicolas.pouillard at gmail.com
Thu Oct 7 17:45:58 EDT 2010


On Thu, 07 Oct 2010 18:03:48 +0100, Peter Wortmann <scpmw at leeds.ac.uk> wrote:
> 
> On Tue, 2010-10-05 at 17:10 -0700, Evan Laforge wrote:
> > +1 for something to solve the "dummy <- m; case dummy of" problem.
> > Here are the possibilities I can think of:
> 
> Might be off-topic here, but I have wondered for a while why Haskell
> doesn't support something like follows:
> 
>   do case (<- m) of ...
> 
> With the more general rule being:
> 
>   do ... e (<- m) g
>     =>
>   ... m >>= \tmp -> e tmp g
> 
> Reasons:
> * "<-" is already "sugary", and the transformation is similar. Just
>   removes the need for the user to define a throw-away name.
> * Better than liftMX and the Applicative operators. As shown, this is
>   more flexible while requiring less magic operators as a bonus. Also
>   makes more clear where the sides effects actually are.
> * Goes well with the spirit of getting the good parts of imperative
>   coding where it potentially makes the code more concise. Can be
>   abused, obviously, but I have also seen a lot of code that I feel   
>   could be written better using this.
> 
> Anything I am overlooking here? I tried to find a discussion about
> something like this, but didn't really know what to look for...

Your notation feels very tempting, however it relies a lot on finding
the "do" to put the bind. Recall that "do" is just syntax, and that
it has no more meaning than its desugaring.

Imagine these examples:

do {a; b (<- c) d; e} => do {a; x <- c; b x d; e}

do {a >> b (<- c) d; e}
  |
  +--> do {x <- c; a >> b x d; e}
  |
  +--> do {a; x <- c; b x d; e}

Imagine that "b" can be equal to "b1 >> b2" and so where placing the
"x <- c" is non obvious and it should be.

On the other hand case (<- m) of {...} being translated into
m >>= \x -> case x of {...} is non-ambigous.

Best regards,

-- 
Nicolas Pouillard
http://nicolaspouillard.fr


More information about the Haskell-Cafe mailing list