When a function with the seq type parameter is a write field, it will no longer accept a list or array

Please see the code below.

let x = Seq.head [1.0; 2.0] // This is ok. type Func<'T> = { f: seq<'T> -> 'T } let func = { f = Seq.head } // Compilation error: This expression was expected to have type seq<obj> but here has type 'a list let y = func.f [1.0; 2.0] let z = func.f ([1.0; 2.0] |> List.toSeq) // This is ok. 

I don’t understand why here the behavior of Seq.head and fund.f is different. This seems like a compiler error. However, if it is by design, can someone help me explain a little? Thank you very much!

+5
source share
1 answer

Below is the answer from Don Syme ( github.com/fsharp ):

This is by design. A rule called "14.4.3 Implicit Nesting of Flexibility to Use Functions and Members" applies only to the use of functions and elements, and not to the use of record fields.

+6
source

All Articles