나는 그것을 알아낼 수 없습니다, 코드 :하스켈 타입 클래스 오류
이smallSum :: (Ord a, Integral a) => a -> a
smallSum n
| n < 0 = 0
| (n < 20) = n + smallSum (n - 1)
| otherwise = error "Number needs to be in 1..10"
fastSumOfSeriesLength :: (Ord a, Integral a) => a -> a
fastSumOfSeriesLength x
| x < 10 = smallSum x
| x >= 10 = sum (take (rest - 1) [dif !! (firstDigit - 1), dif !! (firstDigit - 1) + 100..]) + smallList !! (firstDigit - 1)
where
smallList = [smallSum x | x <- [1..10]]
largeList = [smallSum x | x <- [11..20]]
dif = [l - s | l <- largeList, s <- smallList]
firstDigit = x `mod` 10
rest = x `div` 10
오류 :
ghci> :r
[1 of 1] Compiling Main (learn.hs, interpreted)
learn.hs:194:32:
Could not deduce (a ~ Int)
from the context (Ord a, Integral a)
bound by the type signature for
fastSumOfSeriesLength :: (Ord a, Integral a) => a -> a
at learn.hs:191:26-54
`a' is a rigid type variable bound by
the type signature for
fastSumOfSeriesLength :: (Ord a, Integral a) => a -> a
at learn.hs:191:26
In the first argument of `(-)', namely `rest'
In the first argument of `take', namely `(rest - 1)'
In the first argument of `sum', namely
`(take
(rest - 1)
[dif !! (firstDigit - 1), dif !! (firstDigit - 1) + 100 .. ])'
Failed, modules loaded: none.
임 사람을 찾고가 지적하는 무슨 잘못이 빛 작업을 보일 것이다 무엇 이 오류에 대해 자세히 알아 보려면 Google에 필요한 정보 (!!)
및 take
의 유형 밖으로
빠른 팁 : 함수의 형식 선언을 제거한 다음 GHCi에서로드 할 수 있습니다. ': t expr' 명령으로 함수의 타입을 물어볼 수 있습니다. –