我已经盯着这段代码看了很长一段时间了,我无法理解那个错误信息。
divisors :: Integer -> [Integer]
divisors n = [t | t <- [1..n], mod n t == 0]
length' :: [a] -> Integer
length' [] = 0
length' (x:xs) = 1 + length' xs
divLengths :: [(Integer, Integer)]
divLengths = [(n, length' (divisors n)) | n <- [1..]]
divLengths' :: [Integer]
divLengths' = [length' (divisors n) | n <- [1..]]
hcn :: [Integer]
hcn = [n | n <- [1..], max (take n divLengths') == length' (divisors n)]
"divisors" 接受一个整数并返回一个包含所有除数的列表。
"length'" 与内置的 "length" 相同,只是返回一个 Integer。
“divLengths”是整数元组的无限列表及其除数的数量。
"divLengths'" 只返回数字的除数。
“hcn”应该是一个无限的高度复合数列表(如果除数的数量与所有数字的所有除数的最大值相同(直到被检查的数字))。
但是,尝试在 ghci 中加载 .hs 时出现此错误:
Couldn't match expected type `Integer' with actual type `Int'
In the first argument of `divisors', namely `n'
In the first argument of length', namely `(divisors n)'
In the second argument of `(==)', namely `length' (divisors n)'
你能帮帮我吗?
最好的问候,卢卡斯