具有开放联合的类型定义
1)我有一个开放联合定义如下:
type 'a choice = [> `One | `Other ] as 'a
然后我尝试定义一个类型 choice_list:
type choice_list = choice list
这不起作用。如何定义其中一个或多个组件是开联合的类型?
2)如果我放弃创建 choice_list
类型,而只使用 选择列表
,当我尝试使用选择列表编写接口/签名语句时,
val choice_handler : choice list -> int
编译器会抱怨type 'a choice = 'aconstraint 'a = [>; `一| `Other] 不包含在感染状态类型中。他们有不同的性质
。
我的问题是,如何在接口/签名中编写选择列表的类型声明。
1) I have an open union defined as follows:
type 'a choice = [> `One | `Other ] as 'a
I then try to define a type choice_list:
type choice_list = choice list
which does not work. How does one define types where one or more of the components are open unions?
2) If instead I forgo creating the choice_list
type, and just use a choice list
, when I try writing an interface/signature statement using a choice list,
val choice_handler : choice list -> int
the compiler complains that type 'a choice = 'a constraint 'a = [> `One | `Other ] is not included in type infection_state. They have different arities
.
My question is, how does one write the type declaration of choice list in the interface/signature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器试图告诉您
choice
是一个参数化类型。在类型级别,它的元数为 1。换句话说,您需要提供一个类型参数。您已将参数限制为[`One|`Other]
的子类型,但除此之外它可以是任何类型:如果您想定义选项列表,则额外类型必须来自某处。即,它必须是新类型的参数:(
根据我的经验,此类构造很快就会变得棘手。)
The compiler is trying to tell you that
choice
is a parameterized type. At the type level, it has an arity of 1. In other words, you need to supply one type parameter. You have constrained the parameter to be a subtype of[`One|`Other]
, but other than that it can be any type:If you want to define a list of choices, the extra type has to come from somewhere. I.e., it has to be a parameter to the new type:
(These sorts of constructions get tricky pretty fast, in my experience.)