列表<;T>;F#中的vs.T列表给出了类型错误

列表<;T>;F#中的vs.T列表给出了类型错误,f#,pattern-matching,F#,Pattern Matching,我想要一个函数,它接收seq并返回DateTime*seq。元组的第一部分是传入参数的第一个元素的DateTime,列表是其余元素 我试图用F#这种方式编写代码,但它给出了一个编译器错误: static member TheFunc(lst: seq<DateTime*int>)= match lst with | (h_d, h_i)::tail -> (h_d,tail) | [] -> raise (new ArgumentException

我想要一个函数,它接收
seq
并返回
DateTime*seq
。元组的第一部分是传入参数的第一个元素的
DateTime
,列表是其余元素

我试图用F#这种方式编写代码,但它给出了一个编译器错误:

static member TheFunc(lst: seq<DateTime*int>)=
    match lst with
    | (h_d, h_i)::tail -> (h_d,tail)
    | [] -> raise (new ArgumentException("lst"))
如果我在签名中使用列表而不是序列:

static member TheFunc(lst: List<DateTime*int>)=
    match lst with
    | (h_d, h_i)::tail -> (h_d,tail)
    | [] -> raise (new ArgumentException("lst"))
基金会的静态成员(lst:List)=
匹配lst与
|(hud,hui)::tail->(hud,tail)
|[]->raise(新参数异常(“lst”))
与:

表达式应具有类型
列表
但这里有一种类型
"名单",

你知道为什么这不起作用,以及如何使它起作用吗?

问题是你试图将
序列
列表
相匹配(如错误所示)。你想用

static member TheFunc(lst: seq<DateTime*int>)=
    match lst |> List.ofSeq with
    | (h_d, h_i)::tail -> (h_d,tail)
    | [] -> raise (new ArgumentException("lst"))
基金会的静态成员(lst:seq)=
将lst |>List.ofSeq与
|(hud,hui)::tail->(hud,tail)
|[]->raise(新参数异常(“lst”))
(将列表转换为序列,然后进行模式匹配)

或者,使用

static member TheFunc(lst: list<DateTime*int>)=
基金会的静态成员(lst:list)=
list
中的小写
l
是因为您可能已经打开了
System.Collections.Generic
,并且
列表
与F#
列表

使用
(DateTime*int)list
而不是
列表

如果打开
System.Collections.Generic
,则类型
List
T List
不同。值得注意的是,如果你没有,他们就不是

如果是,那么
List
就是C#中常用的可变列表的一个实例:

令人困惑的是,如果您没有
打开System.Collections.Generic
,它们是相同的:

(* New session *)
> let t0 = typeof<List<int>>
val t0 : Type = Microsoft.FSharp.Collections.FSharpList`1[System.Int32]
> let t1 = typeof<int list>
val t1 : Type = Microsoft.FSharp.Collections.FSharpList`1[System.Int32]    
(*新会话*)
>设t0=typeof
val t0:Type=Microsoft.FSharp.Collections.FSharpList`1[System.Int32]
>设t1=typeof
val t1:Type=Microsoft.FSharp.Collections.FSharpList`1[System.Int32]

好的,很酷,如果我不想使用List.ofSeq,我如何将参数的类型更改为List?
static member TheFunc(lst: list<DateTime*int>)=
> open System.Collections.Generic   
> let t0 = typeof<List<int>>
val t0 : Type = System.Collections.Generic.List`1[System.Int32]
> let t1 = typeof<int list>
val t1 : Type = Microsoft.FSharp.Collections.FSharpList`1[System.Int32]
(* New session *)
> let t0 = typeof<List<int>>
val t0 : Type = Microsoft.FSharp.Collections.FSharpList`1[System.Int32]
> let t1 = typeof<int list>
val t1 : Type = Microsoft.FSharp.Collections.FSharpList`1[System.Int32]