我想写的是:
type A() =
interface IX with ...
interface IY with ...
type B() =
interface IX with ...
interface IY with ...
let mk t : 'T when 'T :> IX and 'T :> IY =
match t with
| Choice1 -> new A()
| Choice2 -> new B()
请注意mk函数返回类型的类型限制。然而,代码不能编译通过,编译器报告无法将A和B转换为“T”的错误。
let x, y = mk Choice1, mk Choice2
,那么x
和y
的类型是什么? - Juliet