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

Evan Laforge qdunkan at gmail.com
Tue Oct 5 20:10:43 EDT 2010


-1 for if then.  The examples of "curried" if then else look, to my
eyes, less readable than the pointed version.  And it's easy enough to
write a 'bool' deconstructor, or an 'ifM' for the monadic case.

+1 for something to solve the "dummy <- m; case dummy of" problem.
Here are the possibilities I can think of:

1) case of:

m >>= case of
    Just _ <- z | guard -> a
    _ -> b

2) habit's case<-

case<- m of
    Just _ <- z | guard -> a
    _ -> b

3) extended lambda (not sure what this would look like... would the
below parse with the give layout?)

m >>= \
    Just _ <- z | guard -> a
    _ -> b

To me, #3 looks less ad-hoc and I like the idea of loosening a
restriction instead of introducing more sugar, but I'm not sure how
the syntax would work out.  Also, from another point of view, 'f x =
...' is sugared to combine a \ and a case, while \ is unsugared, so
tacking some case sugar on to \ would introduce sugar in a previously
sugar-free area.  Of course that \ is already sugared to curry
automatically, but if you rephrase this as "add more sugar" rather
than "loosen a restriction" it suddenly becomes less attractive since
now it's just sugar vs. sugar :)

#2 looks the nicest for this specific use, but seems less general than
#1.  For instance, #1 allows "f = case of { ... } . g".

So I like #1.


More information about the Haskell-Cafe mailing list