casting - What does # (pound sign) mean in type signatures? -
what # mean in type signatures seq<#seq<'a>> compared seq<seq<'a>> ?
this called flexible type. short summary #type means any type inherited type. so, in concrete example seq<#seq<'a>> sequence of collections containing 'a values.
when calling function, f# automatically casts concrete types interfaces - example, can call function taking seq<'a> array 'a[] argument. however, not work when have array of arrays - because 'a[][] implements seq<'a[]> not seq<seq<'a>>.
for example, following 2 functions return list of lengths of nested sequences:
let f1 (s:seq<seq<'t>>) = [ in s -> seq.length ] let f2 (s:seq<#seq<'t>>) = [ in s -> seq.length ] but second 1 can called on lists of lists:
[ [1]; [2;3] ] |> f1 // error fs0001: type 'int list list' not // compatible type 'seq<seq<'a>>' [ [1]; [2;3] ] |> f2 // val : int list = [1; 2]
Comments
Post a Comment