你的法典有三处错误。 在《全球健康标准》中进行编辑并首先提供以下信息:
temp.hs:9:13
Couldn t match expected type `Char with actual type `Int
Expected type: String
Actual type: [Int]
In the first argument of `putStrLn , namely `xs
In the expression: putStrLn xs
这一点非常清楚。 。 Int s. 因此,仅使用<条码>xs而不是<条码>。 解决这一问题(print = pageStrLn . show
)。
接下来的两个问题是:
temp.hs:13:38:
No instance for (Monad ((->) t0))
arising from a use of `return
Possible fix: add an instance declaration for (Monad ((->) t0))
In the expression: return loop (n - 1)
In the expression:
if 0 == n then return () else return loop (n - 1)
In an equation for `loop :
loop n = if 0 == n then return () else return loop (n - 1)
temp.hs:13:45:
Couldn t match expected type `IO ()
with actual type `Int -> IO ()
In the first argument of `return , namely `loop
In the expression: return loop (n - 1)
In the expression:
if 0 == n then return () else return loop (n - 1)
The problem is in the types. loop
is of type Int -> IO ()
. So the first branch of the function is alright, because you return ()
. However, in the else branch, you return something completely different, because return
is not some built-in statement of the language, but a normal function. So return loop (n - 1)
first lifts your loop
function into the monad and than applies it to (n - 1)
.
相反,你想要的是:
loop n = if n == 0 then return () else loop (n - 1)
又注意到你不需要<代码>0=N,因为没有办法意外使用转让而不是平等比较(没有汇编)。
Edit:正如其他答复所指出的,loop
确实没有做任何事情——这只是说自己是1倍,然后是返回()。