Mapping a strict vs. a lazy function

347 Views Asked by At
(head . map f) xs = (f . head) xs

It works for every xs list when f is strict. Can anyone give me example, why with non-strict f it doesnt work?

1

There are 1 best solutions below

0
On

Let's take the non-strict function f = const (), and xs = undefined. In this case, we have

map f undefined = undefined

but

f undefined = ()

and so

(head . map f) undefined = head (map f undefined) = head undefined = undefined

but

(f . head) undefined = f (head undefined) = f undefined = ()

Q.E.D.