interesting example of lazyness/ghc optimisation
01 Mar 2001 08:13:47 +0100
There's something that I've been wanting to ask sombody about, since
it isn't terribly clear to me. Blatantly hijacking a function from
> runRandom last max num
> | num > 1 = runRandom (fst new) max (num-1)
> | otherwise = snd new
While ifs are perhaps more intuitive when there are only two choices
(like here!), and pattern matching matches on the type of arguments
and not (only) their values,
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
Is there a practical difference, and if not, why are there two ways to
skin this particular cat?
Apologies for coming up with a terribly naive question, but I've
looked in the HR without gaining much wisdom (beyond the recipe for
translating if to case).
If I haven't seen further, it is by standing in the footprints of giants