Dan*_*iel 3 f# function-composition
我很好奇为什么会这样
let f = (fun a b -> a, b) >> obj.Equals
Run Code Online (Sandbox Code Playgroud)
给出了错误
没有名为'Equals'的可访问成员或对象构造函数需要1个参数
但这很有效
let f = (fun a -> a, a) >> obj.Equals
Run Code Online (Sandbox Code Playgroud)
没有定义新的组合运算符:
let f = (fun a b -> a, b) >> (<<) obj.Equals
Run Code Online (Sandbox Code Playgroud)
>> (<<) 是一个很好的技巧,也可以扩展为更多的参数:
let compose3 f g = f >> (<<) ((<<) g)
val compose3 : ('a -> 'b -> 'c -> 'd) -> ('d -> 'e) -> ('a -> 'b -> 'c -> 'e)
Run Code Online (Sandbox Code Playgroud)