I am creating a function in F# which is given a list of lists, and which returns true, if all lists are of the same length, except if this length is 0.
I want to specify that the entries of the inner list can be a generic type 'T
, so I was going for
let properTable (input : list list<'T>) : bool =
let lengths = set ([for i in 0..(input.Length-1) -> input.[i].Length])
not (lengths.Contains(0)) && lengths.Count = 1
When pasting this function into F# interactive, I get the error message:
stdin(148,35): error FS0010: Unexpected type application in pattern. Expected ')' or other token.
If I replace the type the type of input
with int list list
, the function works, but I'd like any type, not just an int
.
I can get it to work with only a single list, as in
let testSingleList (input : list<'T>) : bool =
input.Length > 0
How can I accomplish a similar construction, but for a list of lists?
You're mixing two different "styles" of type annotation.
Using either
'T list list
or
List<List<'T>>
should work.