static resolved type parameters expects additional expression

浪子不回头ぞ 提交于 2019-12-13 15:21:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!