问题
The following code
let inline foo< ^T, ^U when ^T : (member foo : (^U -> ^T) -> ^T -> ^T)>
(f:(^U -> ^T)) (t:^T) : ^T =
(^T : (member foo : (^U -> ^T) -> ^T -> ^T) f,t )
yields this error
let inline foo< ^T, ^U when ^T : (member foo : (^U -> ^T) -> ^T -> ^T)> (f:^U) (t:^T) : ^T = (^T : (member foo : (^U -> ^T) -> ^T -> ^T) f,t );;
-----------------------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/stdin(45,96): error FS0735: Expected 3 expressions, got 2
I really dont get why its expecting 2 expressions? Can anybody explain and come up with a working solution?
thx
回答1:
I'm not sure what you're trying to achieve, but this works:
let inline foo< ^T, ^U when ^T : (member foo : (^U -> ^T) -> ^T -> ^T)>
(f:(^U -> ^T)) (t:^T) : ^T =
(^T : (member foo : (^U -> ^T) -> ^T -> ^T) t, f, t)
As I understand it, the first t
is necessary to extract the foo method from the instance of the ^T
type.
Or maybe you wanted the foo method of the ^T
type to be static. In that case, the following code works:
let inline foo2< ^T, ^U when ^T : (static member foo : (^U -> ^T) -> ^T -> ^T)>
(f:(^U -> ^T)) (t:^T) : ^T =
(^T : (static member foo : (^U -> ^T) -> ^T -> ^T) f, t)
来源:https://stackoverflow.com/questions/37854165/static-resolved-type-parameters-expects-additional-expression