[Haskell] Nested guards?

Per Gundberg gundberg at dtek.chalmers.se
Tue Dec 4 18:16:26 EST 2007


Have you looked at the proposed view patterns? It seems like it would
cover the case you gave here. I don't know if there's work being done in
this area though.

http://hackage.haskell.org/trac/ghc/wiki/ViewPatterns

//Gundberg

> Hi,
> 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
> example:
>
> server text
>    | Just xs <- parse text
>    ,   | "field1" `elem` xs   = ... do one thing ...
>        | "field2" `elem` xs   = ... do something else ...
>
> server  _ = ... invalid request ...
>
> As far as I can see this should be a fairly simple change to the
> pattern bindings extension.   Would anyone else find this a useful
> feature, and if so what syntax should we use?
>
> -Iavor
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>




More information about the Haskell mailing list