映射严格与惰性函数

时间:2016-08-29 01:26:09

标签: haskell strictness equational-reasoning

(head . map f) xs = (f . head) xs

当f严格时,它适用于每个xs列表。 任何人都可以举例说明,为什么非严格的f它不起作用?

1 个答案:

答案 0 :(得分:4)

我们选择非严格函数f = const ()xs = undefined。在这种情况下,我们有

map f undefined = undefined

f undefined = ()

等等

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

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

Q.E.D。