【发布时间】:2018-10-04 17:02:23
【问题描述】:
我正在尝试 η-reduce 函数
foldr :: (a -> b -> b) -> b -> BinaryTree a -> b
foldr combiner base tree = foldMap combiner tree base where
foldMap = ...
与
foldMap :: (a -> b -> b) -> BinaryTree a -> b -> b
按预期工作。
我已经 η 减少了
foldr combiner base tree = foldMap combiner tree base
到
foldr combiner = flip $ foldMap combiner where
...
这按预期工作。看来我应该能够完全 η-reduce 以获得无点函数
foldr = flip $ foldMap where
...
但是,这会导致编译错误
Couldn't match type ‘a -> b -> b’ with ‘BinaryTree t0’
Expected type: (a -> b -> b) -> b -> BinaryTree a -> b
Actual type: BinaryTree t0 -> (t0 -> b -> b) -> b -> b
是否有可能进一步减少 η-reduce,如果可以,如何?
【问题讨论】:
-
\combiner -> flip $ foldMap combiner是\combiner -> ($) flip (foldMap combiner),所以你可以看到,eta 不适用:RHS 上的最后一个参数是foldMap combiner,而不是combiner!