我正在寻找斐波那契数列的总和。这就是我坚持的地方:
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
main = do putStrLn "Enter a number:"
num <- readLn
foldr (+) 0 (take num fibs)
错误是:
No instance for (Num (IO t0))
arising from the literal `0'
Possible fix: add an instance declaration for (Num (IO t0))
In the second argument of `foldr', namely `0'
In the expression: foldr (+) 0 (take num fibs)
In the expression:
do { putStrLn "Enter a number:";
num <- readLn;
foldr (+) 0 (take num fibs) }
我到底哪里错了?