Mike Jones writes:
> I am looking at the Hawk Signal module, where the following definition
> occurs:
>
> lift1 f (List xs) = List $ lazyMap f xs
> where
> lazyMap f ~(x:xs) = f x : lazyMap f xs
>
> Now setting aside how the function is used in Hawk, I ran a little
> experiment to see what happens when the irrefutable definition is removed by
> calling it with:
>
> a = List [1, 2]
> b = lift1 (+ 1) a
>
> Now without it I get an error for a "non-exhaustive pattern". With it, I get
> an "irrefutable pattern failed".
Because you used a finite list as input. lazyMap only matches the cons case,
but a finite list always has a nil case. The error messages may be different,
but the problem is the same. Try "take 2 $ lift1 (+ 1) (cycle a)".
> Can some one explain to me the advantages and disadvantages of using
> irrefutable matching, including how irrefutable matching is used in general?
> Why and when it is used, etc.
I'm pretty sketchy on this too.
--
Frank Atanassow, Dept. of Computer Science, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-1012, Fax +31 (030) 251-3791