我认为以下代码应该可以工作:
sum_up x = loop_it 0 x
where loop_it sum i | i > 0 = loop_it sum+i i-1
| i == 0 = sum
但我收到了这个错误:
<interactive>:3:15: error:
• Occurs check: cannot construct the infinite type:
t2 ~ (t0 -> t2) -> t2
Expected type: t2 -> t2
Actual type: t2 -> (t0 -> t2) -> t2
• In an equation for ‘sum_up’:
sum_up x
= loop_it 0 x
where
loop_it sum i
| i > 0 = loop_it sum + i i - 1
| i == 0 = sum
• Relevant bindings include
loop_it :: t2 -> t2 (bound at <interactive>:3:15)
为什么不编译?