gpt4 book ai didi

f# - Seq seq 类型作为 F# 中的成员参数

转载 作者:行者123 更新时间:2023-12-04 01:58:02 28 4
gpt4 key购买 nike

为什么这段代码不起作用?

type Test() =
static member func (a: seq<'a seq>) = 5.

let a = [[4.]]
Test.func(a)

它给出以下错误:
The type 'float list list' is not compatible with the type 'seq<seq<'a>>'

最佳答案

将您的代码更改为

type Test() = 
static member func (a: seq<#seq<'a>>) = 5.

let a = [[4.]]
Test.func(a)

诀窍在于 a 的类型。您需要明确允许外部 seq 保存 seq<'a> 的实例和 seq<'a> 的子类型。使用# 符号可以实现这一点。

关于f# - Seq seq 类型作为 F# 中的成员参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361485/

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