3
我一直在盯着这段代码很长一段时间了,我无法理解这个错误信息。Haskell:实际类型'Int'无法预期类型'Integer'
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)]
“除数”取整数并返回一个列表及其所有除数。
“长度”与内置的“长度”相同,只有它返回一个整数。
“divLengths”是Integer的元组的无限列表及其除数的个数。
“divLengths”只返回数字的除数。
“hcn”应该是一个高度复合数字的无限列表(如果除数的数目与所有数字的所有除数的最大数目相同(直到被检查的数字))。
不过,我得到试图加载名为.hs在ghci中,当这个错误:
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)'
能否请你帮我在这里?
最好的问候, 卢卡斯