【发布时间】:2014-05-03 18:42:50
【问题描述】:
我在某处看到过(抱歉,我找不到参考)这个运算符组合:
(>>)(>>)
其中(>>): (('a -> 'b) -> ('b -> 'c) -> 'a -> 'c) - (>>) 是the function composition operator。
我发现简单的例子很容易理解。例如(>>)f,其中f: i -> i。
(>>)(i -> i) 变为 (i -> 't) -> i -> 't。这是因为('a -> 'b) 被柯里化了,'b 被推断为i 而't 仍然是一个泛型类型。
我不太明白(>>)(>>):
用途
(>>)(>>) 和 (<<)(<<) 将用于什么用途?
为什么需要明确论证?
> (>>)(>>);;
(>>)(>>);;
-^^^^^^
C:\Users\...\Temp\stdin(3,2): error FS0030: Value restriction. The value 'it' has been inferred to have generic type
val it : (((('_a -> '_b) -> '_c -> '_b) -> '_d) -> ('_c -> '_a) -> '_d)
Either make the arguments to 'it' explicit or, if you do not intend for it to be generic, add a type annotation.
根据错误消息的建议:
> let strangeFun arg = (>>)(>>) arg;;
val strangeFun : arg:((('a -> 'b) -> 'c -> 'b) -> 'd) -> (('c -> 'a) -> 'd)
【问题讨论】:
标签: f# type-inference