静态解析类型参数需要附加表达式 [英] static resolved type parameters expects additional expression

查看:58
本文介绍了静态解析类型参数需要附加表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码

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 )

产生此错误

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

我真的不明白为什么它期望2个表达式吗? 有人可以解释提出可行的解决方案吗?

I really dont get why its expecting 2 expressions? Can anybody explain and come up with a working solution?

thx

推荐答案

我不确定您要实现的目标,但这可以起作用:

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)

据我了解,第一个t是从^T类型的实例中提取foo方法所必需的.

As I understand it, the first t is necessary to extract the foo method from the instance of the ^T type.

或者您可能希望^T类型的foo方法是静态的.在这种情况下,以下代码有效:

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)

这篇关于静态解析类型参数需要附加表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆