Pattern guards vs. case (was, unfortunately :Re: interesting example of laziness/ghc optimisation)

Ketil Malde
01 Mar 2001 09:40:48 +0100

(Apologies, I forgot to change the subject)

Laszlo Nemeth <> writes:

> * * * Ketil Malde <> wrote:

> There is no difference. The 'pipe-syntax' (or pattern guards) gets
> desugared (by the pattern matching compiler) to case statements i.e.:

> runRandom = \ last max (num > 1) of
>                              True  -> runRandom (fst new) max (num-1)
>                              False -> snd new

But - the converse is not true, is it?  I can write

     ... = case foo of
                (Foo f) -> ...
                (Bar b) -> ...

but I can't express that as a pattern-guarded expression, can I?  My
impression here is that the PG syntax adds nothing, and is hardly any
more readable, and less intuitive for migrators from more traditional
language.  Why is it there at all?  Is there a (rough) guideline for
when to use one or the other?

> For a more detailed discussion see SPJ's book, Augustsson original
> paper, or M Pettersen't thesis (LNCS 1549). 

Okay, I'll try to look them up.

If I haven't seen further, it is by standing in the footprints of giants