[Haskell] No Pattern Guards

John Meacham john at repetae.net
Mon Mar 28 07:56:38 EST 2005

On Mon, Mar 28, 2005 at 02:17:46PM +0200, Yitzchak Gale wrote:
> I posted a link to the following on the HaskellTwo
> wiki page. Please comment.
> I would like to suggest that PatternGuards NOT be included
> in HaskellTwo.
> While I enjoyed Simon Peyton Jones' well-written
> note on pattern guards
> [http://research.microsoft.com/Users/simonpj/Haskell/guards.html]
> very much, it was written a long time ago.
> Today it is easy to recognize that the problem he
> identifies is just the need for a monad, and that
> his proposed solution is a new syntax for introducing
> monadic calculations. The new syntax is messier and
> less general than the existing "do".

??? There is no conflict between the pattern guard syntax and the do
syntax. in fact they are all of the same family, the most general being
'do' notation, list comprehensions being 'do' notation limited to the
list monad and pattern guards being the 'do' notation limited to the
identity monad. 

> Furthermore, the new syntax confuses the semantics of existing constructs.
> Referring to Simon's principal example in his note,
> here is one way to write "clunky" without PatternGuards:
> > clunky env var1 var2 = fromMaybe (var1 + var2) $ do
> >     val1 <- lookup env var1
> >     val2 <- lookup env var2
> >     return (val1 + val2)

Now generalize it to more than two cases, or one where the second case
needs to pattern match too. The magic of pattern guards is not in a
single guarding expression, but in a function with many different cases
which use pattern guards.

Heh. Pattern guards are perhaps the best thing since sliced bread in my
opinion :). certainly if I were to vote for an extension I couldn't live
without they would be in the top 3.  

Oddly enough, I was looking over the old Haskell discussions, and
pattern guards were supposed to make it into Haskell 98 according to the
decision. Any idea what happened? did someone just forget to write them
up or was there further discussion elsewhere? Old mailing list archives
seem to be hard to come by.



John Meacham - ⑆repetae.net⑆john⑈ 

More information about the Haskell mailing list