我知道在Haskell中,有一个很棒的功能叫做函数组合,这样我们就可以使我们的Haskell代码变得更加简单,比如:
(f . g) x
而不是f (g x)
,foo x $ bar y z
而不是foo x (bar y z)
但是我们可以使用函数组合foo (bar x) (bar y)
吗?
jam*_*idh 13
例如,您可以使用此on
功能
import Data.Function
data Person = Person{name::String, age::Int}
compare `on` age --same as `\x y -> compare (age x) (age y)`
Run Code Online (Sandbox Code Playgroud)