Haskell 哈斯克尔,为什么海德';ghci中的函数正常,但无法编译?
在上面的代码中,我可以将其加载到ghci中并正确调用head函数。 当我把它放进一个文件并试图编译它时。这是错误的。 我不明白这是为什么。需要帮助; 谢谢Haskell 哈斯克尔,为什么海德';ghci中的函数正常,但无法编译?,haskell,Haskell,在上面的代码中,我可以将其加载到ghci中并正确调用head函数。 当我把它放进一个文件并试图编译它时。这是错误的。 我不明白这是为什么。需要帮助; 谢谢 putStrLn采用String(其类型为putStrLn::String->IO()),而不是数字类型。您需要的是打印 [1 of 1] Compiling Main ( head.hs, head.o ) head.hs:7:22: No instance for (Num String) arising
putStrLn
采用String
(其类型为putStrLn::String->IO()
),而不是数字类型。您需要的是打印
[1 of 1] Compiling Main ( head.hs, head.o )
head.hs:7:22:
No instance for (Num String) arising from the literal `4'
Possible fix: add an instance declaration for (Num String)
In the expression: 4
In the first argument of head', namely `[4, 5, 6]'
In the expression: head' [4, 5, 6]
print
可以采用具有Show
实例的任何类型。它的类型是print::Show a=>a->IO()
putStrLn
采用字符串(它的类型是putStrLn::String->IO()
),而不是数字类型。您需要的是打印
[1 of 1] Compiling Main ( head.hs, head.o )
head.hs:7:22:
No instance for (Num String) arising from the literal `4'
Possible fix: add an instance declaration for (Num String)
In the expression: 4
In the first argument of head', namely `[4, 5, 6]'
In the expression: head' [4, 5, 6]
print
可以采用具有Show
实例的任何类型。它的类型是print::Show a=>a->IO()
...
print ret