haskell - Mapping a strict vs. a lazy function -
(head . map f) xs = (f . head) xs
it works every xs list when f strict. can give me example, why non-strict f doesnt work?
let's take non-strict function f = const ()
, , xs = undefined
. in case, 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.
Comments
Post a Comment