[英]Couldn't match type `[Char]' with `Char'
I have the following code: 我有以下代码:
nonstopfreq :: Eq a => [a] -> [(a,Int)] -> [(a,Int)]
nonstopfreq (x : xs) (y : ys) = nonstopfreq xs (filter (\y -> not (x == fst y)) ys)
where the arguments are: 其中的参数是:
String
. String
列表。 [([String],Int)]
[([String],Int)]
but I get the following error, because? 但出现以下错误,是因为?
Couldn't match type `[Char]' with `Char'
Expected type: [(String, Int)]
Actual type: [([String], Int)]
In the second argument of `nonstopfreq', namely `aPrimerB'
In the expression: nonstopfreq lStopWords aPrimerB
In an equation for `aSegon':
aSegon = nonstopfreq lStopWords aPrimerB
What I am trying to eliminate the elements listed and the tuple. 我正在尝试消除列出的元素和元组。
AprimerB
is: [(["the"],1818),(["and"],940),(["to"],809),(["a"],690),(["of"],631),(["it"],545),(["she"],542),(["said"],462),(["you"],435),(["in"],431)]
. AprimerB
是: [(["the"],1818),(["and"],940),(["to"],809),(["a"],690),(["of"],631),(["it"],545),(["she"],542),(["said"],462),(["you"],435),(["in"],431)]
。 The other argument, lStopWords
, has type as obtained from words
: 另一个参数
lStopWords
具有从words
获取的类型:
do
...
stopWords <- hGetContents fileStopWords
let lStopWords = words stopWords
What I try is to remove AprimerB
items shown in LstopWords
. 我尝试是消除
AprimerB
中显示的项目LstopWords
。
Well, the problem is that lStopWords
is simply a list of strings (of words, in this particular case) – ie, [a] ~ [String]
or a ~ String
. 好了,问题是,
lStopWords
仅仅是一个字符串列表(的话,在这种特殊情况下) -即, [a] ~ [String]
或者a ~ String
。 That means the second argument with its general type [(a, Int)]
becomes [(String, Int)]
. 这意味着一般类型为
[(a, Int)]
的第二个参数变为[(String, Int)]
。 However, you've passed 但是,您已经通过了
aPrimerB = [(["the"],1818), (["and"],940) ... ]
where each of the strings is contained in a singleton list. 其中每个字符串都包含在一个单例列表中。 So the type of this is
[([String], Int)]
. 因此,此类型为
[([String], Int)]
。 Since each list has just one argument, you can actually change it easily to 由于每个列表只有一个参数,因此您实际上可以轻松地将其更改为
aPrimerB :: [(String, Int)]
aPrimerB = [("the",1818), ("and",940) ... ]
which will get rid of that error. 这将摆脱该错误。
Alternatively, you can also wrap every element of the words list in another singleton-list layer. 或者,您也可以将单词列表的每个元素包装在另一个单例列表层中。
let lStopWords :: [[String]]
lStopWords = map (:[]) $ words stopWords
Then you can keep the old definition of aPrimerB
, because now a ~ [String]
. 然后,您可以保留
aPrimerB
的旧定义,因为现在a ~ [String]
。 The result would be basically the same, but the singleton lists seem pretty useless here. 结果基本上是相同的,但是单例列表在这里似乎毫无用处。
Note that even with that error fixed, nonstopfreq
will still not work: there is no base case, so it will crash when either of the lists is empty. 请注意,即使已修复该错误,
nonstopfreq
仍将不起作用:没有基本情况,因此当其中一个列表为空时,它将崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.