Search code examples
f#sequencesstatic-members

Seq seq type as a member parameter in F#


why does not this code work?

type Test() =
  static member func (a: seq<'a seq>) = 5.

let a = [[4.]]
Test.func(a)

It gives following error:

The type 'float list list' is not compatible with the type 'seq<seq<'a>>'

Solution

  • Change your code to

    type Test() = 
      static member func (a: seq<#seq<'a>>) = 5. 
    
    let a = [[4.]] 
    Test.func(a) 
    

    The trick is in the type of a. You need to explicitly allow the outer seq to hold instances of seq<'a> and subtypes of seq<'a>. Using the # symbol enables this.