【发布时间】:2012-06-13 00:38:35
【问题描述】:
用点符号表示:
absoluteError x y = abs (x-y)
一个不明确的无点表示法示例:
absoluteError' = curry (abs . uncurry (-))
【问题讨论】:
-
如果用尖锐的符号很清楚,那有什么问题呢?这看起来像是那种必须通过心理转换来阅读任何无点版本的示例......
用点符号表示:
absoluteError x y = abs (x-y)
一个不明确的无点表示法示例:
absoluteError' = curry (abs . uncurry (-))
【问题讨论】:
您可以通过以下小步骤自行推导出它:
absoluteError x y = abs (x-y) = abs ((-) x y) = abs ( ((-) x) y)
= (abs . (-) x) y = ( (abs .) ((-) x) ) y =
= ( (abs .) . (-) ) x y
所以,eta-reduction,如果f x y = g x y 我们得出结论f = g。
进一步,暂时使用_B = (.),
(abs .) . (-) = _B (abs .) (-) = _B (_B abs) (-) = (_B . _B) abs (-)
= ((.) . (.)) abs (-)
【讨论】:
这里有一些方法。
absoluteError = (abs .) . (-)
absoluteError = ((.) . (.)) abs (-)
将胸部操作员命名为政治上更正确的名称(到底是什么,同时概括它)
(.:) = fmap fmap fmap
absoluteError = abs .: (-)
使用semantic editor combinators:
result :: (o1 -> o2) -> (i -> o1) -> (i -> o2)
result = (.)
absoluteError = (result . result) abs (-)
当然,这些都是一样的把戏,只是名字不同而已。享受吧!
【讨论】:
.: 没有在任何地方定义为标准?还是这样?