Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 哈斯克尔,为什么海德';ghci中的函数正常,但无法编译?_Haskell - Fatal编程技术网

Haskell 哈斯克尔,为什么海德';ghci中的函数正常,但无法编译?

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

在上面的代码中,我可以将其加载到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 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