当具有seq类型参数的函数是记录字段时,它将不再接受列表或数组

app*_*umb 5 f#

请参阅以下代码.

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.
Run Code Online (Sandbox Code Playgroud)

我不明白为什么Seq.head和fund.f的行为在这里有所不同.它对我来说看起来像编译器错误.但是,如果这是设计的,有人可以帮我解释一下吗?非常感谢!

app*_*umb 6

以下是Don Syme(github.com/fsharp)的答案:

这是设计的.称为"14.4.3对函数和成员的使用的灵活性的隐式插入"的规则仅适用于函数和成员的使用,而不是记录字段的使用.