Heribert Schuetz:
> 3. From Alex' example (version 5a) one could have learned that we do not
> need guards at all, because all sorts of guards (today's Haskell
> guards, Peyton-Jones-style guards, and nested guards) can be replaced
> by the Maybe monad in a *straightforward* way:
I don't know if Heribert suggests this in earnest, or as a reductio
ad absurdum of my suggestion, but it's certainly not what I was
getting at. Rather, I was questioning whether the extra power of
having pattern guards yield a Maybe Monad(Plus|Zero) value was
worth the syntactic encumberance. Judging by the proffered example
(version 5), I don't think it is, although I'm willing to be
convinced, if someone has an example which seems to cry out for
simultaneous use of pattern-guards, and monadic plus.
> 5. The more I think about it, the more I am in favour of Simon's
> qualifier lists (i.e., without nesting), but with semantics according
> to the Maybe monad. It has several advantages (the last one being the
> most important one in my eyes):
>
> - The syntax is not a problem:
>
> clunky env var1 var1 | val1 <- lookup env var1,
> val2 <- lookup env var2
> = val1 + val2
> ...other equations for clunky...
The syntax here isn't clunky, I'll give you that, but if one wanted
to pattern-guard with anything other than a Maybe (and Simon produced
a couple of such examples), then things would start to look rather
awkward again.
> - It does not need the explananation of a new semantics for "<-" with
> a non-monadic expression on the RHS.
I don't see this as a real advantage. It just changes the rationale
from one restricted monadic case (a mutated version of Id), to an
equally restricted version on another Monad, neither of which is
truly consistent with both the other uses of "<-", which take arbitrary
monads. Not that either upsets me greatly, just that I don't see it
as arguing for one over the other.
> - What are the possible results of pattern matching? It may fail or
> succeed, and in the latter case some data is available. This is
> exactly what Maybe has been introduced for.
I agree there's a certain intuitive corresponance here, and possibly
some practical utility. (The ability to use Nothing as the "FAIL"
of pattern-matching translation, if one wanted it, say.)
Slainte,
Alex.