[Haskell-cafe] Re: Lambda-case / lambda-if
Lauri Alanko
la at iki.fi
Thu Oct 7 18:13:20 EDT 2010
On Thu, Oct 07, 2010 at 02:45:58PM -0700, Nicolas Pouillard wrote:
> On Thu, 07 Oct 2010 18:03:48 +0100, Peter Wortmann <scpmw at leeds.ac.uk> wrote:
> > 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
Your "general" rule doesn't subsume your case example, since a case
expression is not an application. I think you mean something like
do C[(<- m)]
=>
m >>= \tmp -> C[tmp]
where C is an arbitrary expression context. It could further be
generalized to allow several (<- ...) subterms in an expression, with
implied left-to right sequencing. Frankly, that seems like a very
attractive way to make the do-notation into a more practical
imperative sub-language.
This should probably also cover binding, i.e. do { p <- C[(<- m)];
... } should also work.
> 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}
To my understanding no rule would produce this latter variant. do {a;
b} is transformed into a >> do {b}, not the other way around. The
proposed transformation rule seems clear to me: the context covers the
entire expression-statement, including of course expressions
containing monadic operations:
do {a >> b (<- c) d; e} => c >>= \x -> a >> b x d >> e
and if you want a to go before c, you have to do
do {a; b (<- c) d; e) => a >> c >>= \x -> 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.
I don't see what this has to do with anything. All we are interested
in is the syntax of do-expressions. The do-transformation is
completely oblivious to monadic operations within the statements, it
only produces some more monadic operations.
Cheers,
Lauri
More information about the Haskell-Cafe
mailing list