我正在尝试编译一个非常简单的haskell程序.我不知道如何在Haskell中对语句(表达式)进行排序,或者没有办法做到这一点.
我基本上想要一个表单的功能:
f = <do stuff 1>
<do stuff 2>
...
Run Code Online (Sandbox Code Playgroud)
以下应该模拟的模式
<do stuff>
<tail recursion>
Run Code Online (Sandbox Code Playgroud)
但编译失败:
go 0 = 0
go i = case i of
1 -> 2
_ -> 3
go (i-1)
Run Code Online (Sandbox Code Playgroud)
这也不起作用(更简单,没有递归):
go i = 1
2
Run Code Online (Sandbox Code Playgroud)
上面的代码直接编译,但在运行时我得到了神秘的:
No instance for (Num (a0 -> t0))
arising from a use of `go'
Possible fix: add an instance declaration for (Num (a0 -> t0))
In the expression: go 2
In an equation for `it': it = go 2 …Run Code Online (Sandbox Code Playgroud) haskell ×1