f# - 获取 FS0035 => 构造已弃用

标签 f# compiler-errors deprecated fsyacc fslex

在基于 fsyacc 的项目中,我有这一行:

type 'a cucomment = string

这是我得到的完整错误描述:

CALast.fs(117,9): error FS0035: This construct is deprecated: This type abbreviation has one or more declared type parameters that do not appear in the type being abbreviated. Type abbreviations must use all declared type parameters in the type being abbreviated. Consider removing one or more type parameters, or use a concrete type definition that wraps an underlying type, such as 'type C<'a> = C of ...'.

知道如何解决这个问题吗?

最佳答案

F# 不再允许在不声明新类型的情况下将泛型类型参数添加到类型的类型别名。如果你想定义一个包装其他类型的通用类型,你必须使用一些构造函数。例如,您可以使用单大小写区分联合:

type 'a Cucomment = CC of string

不幸的是,这意味着您必须更改所有使用该类型的代码,以便使用模式匹配或通过向该类型添加 Value 成员来解包值。

唯一允许通用类型别名的情况是当您声明一个带有度量单位的类型版本时,这需要一个特殊属性。但是,这可能对您不起作用(因为单位的行为完全不同):

[<MeasureAnnotatedAbbreviation>]
type 'a Cucomment = string 

如果这是由 fsyacc 生成的某些代码,那么这是 fsyacc 中的错误,应该修复(我认为这是最近的更改)。在这种情况下,请将其报告给 microsoftcom 上的 fsbugs

关于f# - 获取 FS0035 => 构造已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9838098/

相关文章:

list - F# If 语句类型不匹配

java - 使用泛型编译错误

javascript - 替代 .selector 属性,现在它已在 jQuery 1.9 中删除

node.js - ExpressJS 错误 : Body-Parser Deprecated

rust - 如何正确弃用一个 crate 特性

f# - 如何在 FParsec 中添加解析后的数字必须满足的条件?

f# - 通过类型分析的功能程序示例 'writing themselves'

f# - 为通用应用程序(又名商店应用程序或 Windows 应用程序或 WinRT 应用程序)创建 F# PCL

c++ - 如何修复 pimpl 实现中预期的主表达式编译错误?

c++ - 使用 C++ 模板编译类成员变量?