F#中类型约束的顺序 [英] Order of type constraints in F#

查看:103
本文介绍了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.

这篇关于F#中类型约束的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆