我已经盯着这段代码有一段时间了,但我无法理解该错误消息。
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”相同,只是它返回一个整数。
“divLengths”是 Integer 及其除数的元组的无限列表。
“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)'
你能帮我一下吗?
此致,
卢卡斯