Haskell Error - Naked Expression at Top Level

后端 未结 1 1432
我在风中等你
我在风中等你 2021-02-05 02:06

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,

相关标签:
1条回答
  • 2021-02-05 02:39

    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
    

    or

    main = print (fib 5)
    
    0 讨论(0)
提交回复
热议问题