[Haskell] Re: Nested guards?
Christian.Maeder at dfki.de
Wed Dec 5 05:40:48 EST 2007
Iavor Diatchki wrote:
> Lately I have been using pattern guards more than usual and I find
> that occasionally I need to nest them (i.e., I have alternatives with
> a common prefix). This seems to happen when I need to do some
> preliminary checking, followed by some decision making. Here is an
> server text
> | Just xs <- parse text
> , | "field1" `elem` xs = ... do one thing ...
> | "field2" `elem` xs = ... do something else ...
> server _ = ... invalid request ...
Not having used pattern guards so far, can't you write?
server text = case parse text of
| "field1" `elem` xs -> ... do one thing ...
| "field2" `elem` xs -> ... do something else ...
_ -> ... invalid request ...
More information about the Haskell