F#中类型约束的顺序
问题描述:
这在F#4.0中有效:
This works in F#4.0:
type Something<'a, 'b when 'b :> seq<'b>>() =
这不是:
type Something<'b when 'b :> seq<'b>, 'a>() =
类型名称中的意外符号','.预期为>"或其他令牌.
Unexpected symbol ',' in type name. Expected '>' or other token.
类型约束的顺序重要的原因是什么?
What's the reason that the order of the type constraint matter?
答
因为它在规范中-相关的部分是这样(从第5节开始):
Because it is in the spec - the relevant part is this (from the start of section 5):
typar-defns:= < typar-defn, ..., typar-defn typar-constraints_opt>
约束必须走到最后.
在此typar-constraints
中,必须始终以when
开头,并且不能出现在其他任何地方.
In this typar-constraints
must always start with when
and can't appear anywhere else.