Search code examples
f#valuetuple

Why is it impossible to declare a type alias to an F# struct tuple?


It is impossible to define a type alias to a struct tuple in F#. Only with a workaround, it works.

let x = struct (1, 2)
> val x : struct (int * int) = struct (1, 2)

let y : struct (int * int) = struct (4, 5) // explicit type
> val y : struct (int * int) = struct (4, 5)

type S = struct (int * int) // straight definition
> error FS0010: Unexpected symbol '(' in member definition

type S = ValueTuple<int, int> // workaround
> [<Struct>]
  type S = struct (int * int)

Is the error for "type S = struct (int * int)" a compiler bug?


Solution

  • Tried to file a bug and found the answer here: https://github.com/dotnet/fsharp/issues/7014

    parenthesis around the type are required:

    type Alias = (struct(int * int))