Home > front end >  Cannot declare a member of a Discriminated Union
Cannot declare a member of a Discriminated Union

Time:05-23

The following code gives an compilation error about being "not sufficiently generic". What is wrong?

type SameLenVectors<'T when 'T: (static member ( ): 'T * 'T -> 'T) and 'T: (static member (*): 'T * 'T -> 'T)> =
    private SameLenVectors of 'T list list
        member this.Item = 1

CodePudding user response:

'T is a statically resolved type parameter (SRTP), so it must be inlined at the call site:

member inline this.Item = 1

It's a bit confusing, since you've declared the type parameter as 'T rather than ^T, but it's an SRTP nonetheless (as evidenced by the compiler error).

  • Related