2
我想实现阶乘的尾递归版本:无法构造无限类型 - 实施尾递归阶乘计算器
let{factorial 0 n = n; factorial x n = factorial (x-1, n * x)}
我得到这个:
<interactive>:1:41:
Occurs check: cannot construct the infinite type: t1 = t1 -> t1
In the return type of a call of `factorial'
In the expression: factorial (x - 1, n * x)
In an equation for `factorial':
factorial x n = factorial (x - 1, n * x)
<interactive>:1:52:
Occurs check: cannot construct the infinite type: t0 = (t0, t1)
In the first argument of `(-)', namely `x'
In the expression: x - 1
In the first argument of `factorial', namely `(x - 1, n * x)'
<interactive>:1:61:
Occurs check: cannot construct the infinite type: t1 = (t0, t1)
In the second argument of `(*)', namely `x'
In the expression: n * x
In the first argument of `factorial', namely `(x - 1, n * x)'
我如何构建无限类型在这里? (使用GHCI 7.0.1)
如果您给定义类型签名,错误消息通常更容易理解。你会得到一些与''无法匹配预期类型'Integer'和实际类型'(t0,t1)'''''一致的东西。 – 2012-07-24 20:20:36