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

Popular posts from this blog

javascript - How do you prevent nested queries/catches in sequelize? -

java - Could not retrieve pre-bound Hibernate session - Could not obtain transaction-synchronized Session for current thread -

java - ConcurrentModificationException upon committing transaction with Hibernate -