在此代码中存在错误起因以致不匹配。由于类型不匹配导致的代码中的错误
import System.IO
loop :: Int -> [Int] -> IO()
loop 0 ls = return ls
loop n ls = do newNumber <- readLn
loop (n-1) (newNumber:ls)
main = do
putStrLn "Please enter the number"
number <- readLn :: IO Int
putStrLn $ "The num is:" ++ show number
xs <- loop number []
print xs
的错误信息是:
treep.hs:4:20:
Couldn't match expected type `()' with actual type `[Int]'
In the first argument of `return', namely `ls'
In the expression: return ls
In an equation for `loop': loop 0 ls = return ls
如何删除错误
@tikhon请看这段代码 – 2012-01-16 08:55:55
你想用'循环'功能完成什么?它的签名表示它需要一个整数('Int')整数列表('[Int]')并返回一个操作。 – Andre 2012-01-16 09:10:48
我想让循环运行n次,并最终返回n个数字列表 – 2012-01-16 09:13:00