interesting example of laziness/ghc optimisation
Laszlo Nemeth
laszlo@ropas.kaist.ac.kr
Thu, 1 Mar 2001 16:37:58 +0900 (KST)
* * * Ketil Malde <ketil@ii.uib.no> wrote:
> > runRandom last max num
> > | num > 1 = runRandom (fst new) max (num-1)
> > | otherwise = snd new
>
> What's the difference between the pipe-syntax, and a case statement,
> i.e. writing the function as
>
> runRandom last max num = case num of
> 1 -> runRandom ....
> otherwise -> snd new
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.case (num > 1) of
True -> runRandom (fst new) max (num-1)
False -> snd new
For a more detailed discussion see SPJ's book, Augustsson original
paper, or M Pettersen't thesis (LNCS 1549).
HTH,
--laszlo