Getting FS0035 => Construct is deprecated

1k views Asked by At

In a fsyacc based project, I have this line:

type 'a cucomment = string

This is the full error description I'm getting:

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 ...'.

Any idea how to solve this?

1

There are 1 answers

0
Tomas Petricek On BEST ANSWER

F# no longer allows type aliases that add generic type parameters to a type without declaring a new type. If you want to define a generic type that wraps some other type, you have to use some constructor. For example, you can use single-case discriminated union:

type 'a Cucomment = CC of string

Unfortunately, this means that you'd have to change all code that uses the type to unwrap the value using pattern matching or by adding Value member to the type.

The only case where generic type aliases are allowed is when you declare a version of type with units of measure, which requires a special attribute. However, this is probably not going to work for you (because units behave quite differently):

[<MeasureAnnotatedAbbreviation>]
type 'a Cucomment = string 

If this is in some code generated by fsyacc, then that's a bug in fsyacc that should be fixed (I think this was quite recent change). In that case, report it to fsbugs at microsoft dot com.