Pattern guards vs. case (was, unfortunately :Re: interesting example
of laziness/ghc optimisation)
Laszlo Nemeth
laszlo@ropas.kaist.ac.kr
Thu, 1 Mar 2001 20:25:28 +0900 (KST)
* * * Johannes Waldmann wrote:
> > But if you want to be really weird you can write something
> > like (I haven't typed this in):
> >
> > f x | (Foo _) == x =
> > f x | (Bar _) == x =
>
> no, you can't, e. g. hugs (Feb 2000) says
>
> Prelude> let f x | Just 4 == x = 0 in f (Just 4)
> 0
> Prelude> let f x | Just _ == x = 0 in f (Just 4)
> ERROR: Illegal `_' in expression
So it works with (Just 4), but it doesn't with (Just _)? I can't see
anything in the syntax (Haskell report pg 127, 128) which rules the
second one out. Though, I'd try it with parenthesis. Shall we call it
a bug (unless I am missing something obvious)?
--laszlo