#(井号)在类型签名中意味着什么?

Gos*_*win 16 f# symbols casting type-signature

类型签名中的#含义seq<#seq<'a>>与刚刚相比是什么意思seq<seq<'a>>

Tom*_*cek 25

这称为灵活类型.简短摘要是#type指从中继承的任何类型type.因此,在您的具体示例中,seq<#seq<'a>>将是包含'a值的任何集合的序列.

在调用函数时,F#会自动将具体类型转换为接口 - 例如,您可以将seq<'a>使用数组'a[]作为参数的函数调用.但是,当您有阵列数组时,这不起作用 - 因为'a[][]只有实现seq<'a[]>但不是seq<seq<'a>>.

例如,以下两个函数返回嵌套序列的长度列表:

let f1 (s:seq<seq<'T>>) = [ for i in s -> Seq.length i ]
let f2 (s:seq<#seq<'T>>) = [ for i in s -> Seq.length i ]
Run Code Online (Sandbox Code Playgroud)

但只有第二个可以在列表列表上调用:

[ [1]; [2;3] ] |> f1
// error FS0001: The type 'int list list' is not 
// compatible with the type 'seq<seq<'a>>'

[ [1]; [2;3] ] |> f2
// val it : int list = [1; 2]
Run Code Online (Sandbox Code Playgroud)