(x : ^T) = x >>) : ^T * int -> ^T) > (x : ^T) = x >>> 1 错误: 尝试将其解析为运算符名称,但失败 -6ren">
gpt4 book ai didi

f# - 静态类型变量、成员约束、编译器错误? ("Attempted to parse this as an operator name, but failed")

转载 作者:行者123 更新时间:2023-12-03 07:32:58 25 4
gpt4 key购买 nike

编译:

let inline f< ^T when ^T : (static member (<<<) : ^T * int -> ^T) > (x : ^T) = x <<< 1

不编译:
let inline f< ^T when ^T : (static member (>>>) : ^T * int -> ^T) > (x : ^T) = x >>> 1

错误:
  • 尝试将其解析为运算符名称,但失败
  • 成员签名中出现意外符号“>”。应为 ')' 或其他标记。
  • 类型参数缺少约束 'when ^T : (static member ( >>> ) : ^T * int32 -> ^T)'

  • 添加空格无济于事;这一行产生了相同的编译器错误:
    let inline f< ^T when ^T : (static member ( >>> ) : ^T * int -> ^T) > (x : ^T) = x >>> 1

    我已经搜索了文档和规范,但无济于事。这是一个错误吗?有没有办法在成员签名中包含 > 字符?

    最佳答案

    当然看起来像一个错误。这很丑陋,但一种解决方法是使用运算符名称的长格式:

    let inline f< ^T when ^T : (static member op_RightShift : ^T * int -> ^T)> (x : ^T) =
    x >>> 1

    关于f# - 静态类型变量、成员约束、编译器错误? ("Attempted to parse this as an operator name, but failed"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14990142/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com