1 haskell higher-order-functions
这是一个众所周知的成语吗?
applyTwice :: (a -> b -> c) -> (d -> a) -> (d -> b) -> (d -> c)
applyTwice g f1 f2 p = g (f1 p) (f2 p)
Run Code Online (Sandbox Code Playgroud)
这是一个典型的用途:
applyTwice someFunction head tail $ this $ that $ otherThing
Run Code Online (Sandbox Code Playgroud)
在这种情况下,this $ that $ otherThing返回一个列表,我想利用这两个头部和该列表的尾部,然后将两端供给someFunction.
是applyTwice一个标准的习惯用语,还是有一些更自然的方法来获取复杂计算结果的头部和尾部?只是使用where标准方式来做到这一点?
不是liftM2吗?.