本文介绍了Haskell错误 - 顶级裸体表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
I have the following code:
fib n
| n == 0 = 0
| n == 1 = 1
| n > 1 = fib (n-1) + fib (n-2)
print fib 5
由于某种原因,它抛出了一个错误:
And for some reason, it's throwing an error:
[1 of 1] Compiling Main ( test.hs, test.o )
test.hs:8:1: Parse error: naked expression at top level
发生了什么事?
推荐答案
顶层不能有表达式。 Haskell程序入口点是 Main
模块中的 main
函数。还有 print fib 5
调用 print
有两个参数,您需要这样做:
You cannot have an expression at the top-level. Haskell program entry point is a main
function in Main
module. Also print fib 5
calls print
with two arguments, you need to do:
main = print $ fib 5
或
main = print (fib 5)
这篇关于Haskell错误 - 顶级裸体表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!