该表达式应该具有类型列表<char>,但这里有类型&#39;列表

时间:2015-11-11 19:27:24

标签: f#

我有以下代码:

函数numbersDictionary尝试创建关联数组,takeVal尝试获取相应键的值。

let numbersDictionary =
 let d = [('I', 1); ('V', 5); ('X', 10); ('L', 50); ('C', 100); ('D', 500); ('M', 1000)] |> Map.ofList
 d

let takeVal par = 
    match par with
        | Some(v) ->  v
        | None -> 0 


let rec evaluate( numbersInchar:List<char>)=
    match numbersInchar with
    |[] -> []
    |head::tail -> takeVal (numbersDictionary.TryFind head)::evaluate tail

在匹配|[] -> []的第一行,我遇到了以下的错误:

This expression was expected to have type  list<char> but here has type 'a list 

我既不能解释这个问题也不能解决它。

请帮帮我。

1 个答案:

答案 0 :(得分:0)

>>> a,b = zip(*[i.split('.') for i in d])
>>> a
('a1', 'a2', 'a3')
>>> b
('b1', 'b2', 'b3')