Why is the ref type passed to the F # function that expects a byref type error?

let a = ref 0
let f (x: byref<int>) = x

f a // type error

System.Int32.TryParse("123",a) // works

f abeing a type error is puzzling, because it acan be passed to .NET library methods with a type byref<int>. Why?

Edit: I think I really explained this question poorly. Type System.Int32.TryParse- string * byref<int> -> boolbut it works. So why can't I pass ain a type function x:byref<int> -> int? That is all I ask.

+4
source share
2 answers

8.13.7 F # spec. ref, byref, ", ", , .

+5

, , - , :int ref byref<int>

:

let a = ref 0
let f (x: int ref) = x

f a // type error

System.Int32.TryParse("123",a) // works

: , . F #, , F # . , , # , , . , byref<int>, .NET , out, out #. .

+1

Source: https://habr.com/ru/post/1682555/


All Articles