gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:32:45 26 4
gpt4 key购买 nike

请看下面的代码。

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.

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

最佳答案

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

This is by design. The rule called "14.4.3 Implicit Insertion of Flexibility for Uses of Functions and Members" is only applied to uses of functions and members, not uses of record fields.

关于f# - 当带有 seq 类型参数的函数是记录字段时,它将不再接受列表或数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37903022/

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