ref和byref<&燃气轮机;F#类成员中的参数
我将一些f#函数定义重写为静态成员,并停留在ref/byref参数错误:ref和byref<&燃气轮机;F#类成员中的参数,f#,F#,我将一些f#函数定义重写为静态成员,并停留在ref/byref参数错误: static member bar (a : byref<int>) = Foo.bar &a Error FS0001 This expression was expected to have type 'int ref' but here has type 'byref<'a>' 静态成员栏(a:byref)=Foo.bar&a 错误FS0001此表
static member bar (a : byref<int>) = Foo.bar &a
Error FS0001 This expression was expected to have type
'int ref'
but here has type
'byref<'a>'
静态成员栏(a:byref)=Foo.bar&a
错误FS0001此表达式应具有类型
“int ref”
但这里有一种类型
'byref类型Foo()=
静态杆件(a:byref)=
那么是0吗
System.Console.Write(a.ToString());福安
否则a;;
Foo型=
班
新:单位->Foo
静态成员栏:a:byref->int
结束
>设可变b=3;;
val可变b:int=3
>福巴酒店;;
福巴酒店;;
--------^^
stdin(71,9):错误FS0001:此表达式应具有类型
“int ref”
但这里有一种类型
“byrefint ref
是F#的类型定义,而byref不可能在没有看到最小可重复示例的情况下说出错误。你能分享代码的其他部分吗,特别是Foo.bar
的定义?@TomasPetricek对不起,我想这是很清楚的。我已向中添加了其他信息question@KovalevRoman我已将您的代码复制到fsi,并按预期工作。请确保您没有覆盖F#interactive会话中的定义。@TomasPetricek绝对没有,这是VS 2017中默认的F#interactive版本4.1抱歉,我认为这是清楚的。我在问题中添加了额外的信息
> let rec foo (a :byref<int>) =
a <- a-1
if a > 0 then
System.Console.Write(a.ToString()); foo &a
else a
;;
val foo : a:byref<int> -> int
> let mutable a = 3;;
val mutable a : int = 3
> foo &a;;
21val it : int = 0
> type Foo() =
static member bar (a : byref<int>) =
a <- a-1
if a > 0 then
System.Console.Write(a.ToString()); foo &a
else a;;
type Foo =
class
new : unit -> Foo
static member bar : a:byref<int> -> int
end
> let mutable b = 3;;
val mutable b : int = 3
> Foo.bar &b;;
Foo.bar &b;;
--------^^
stdin(71,9): error FS0001: This expression was expected to have type
'int ref'
but here has type
'byref<'a>'