这是一个纯粹的学术问题,但来自 this question
关于类型约束。提问者举了一个例子:
type Something<'a, 'b when 'b :> seq<'b>>() =
member __.x = 42
f# 愉快地编译。现在的问题是你如何制作这个对象?
let z = new Something<???, ???>()
最佳答案
type T() =
interface seq<T> with
member this.GetEnumerator() = ([] :> seq<T>).GetEnumerator()
member this.GetEnumerator() = ([] :> seq<T>).GetEnumerator() :> System.Collections.IEnumerator
let z = new Something<string, T>()
关于types - 不可能用递归类型约束创建对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37578528/