[英]Haskell Error; Occurs check: cannot construct the infinite type: t ~ [t]
[英]Recursion in conditional definition in Haskell gives error ( Occurs check: cannot construct the infinite type:)
我想定义一个条件函数并在Haskell(ghci 7.x)中使用递归,如:
partitions n k m = gfunct n k m
where
gfunct n k m
| n == 0 && k == 0 = 1
| n < m || k == 0 = 0
| otherwise = gfunct (n-m,k-1,m+1) + gfunct (n,k,m+1)
我收到一个错误:
fib.hs:20:35:
Occurs check: cannot construct the infinite type:
a1 ~ t6 -> (t5, t6, t7) -> a1
Relevant bindings include
m :: (t5, t6, t7) (bound at fib.hs:17:23)
k :: t6 (bound at fib.hs:17:21)
n :: (t5, t6, t7) (bound at fib.hs:17:19)
gfunct :: (t5, t6, t7) -> t6 -> (t5, t6, t7) -> a1
(bound at fib.hs:17:12)
In the first argument of ‘(+)’, namely
‘gfunct (n - m, k - 1, m + 1)’
In the expression:
gfunct (n - m, k - 1, m + 1) + gfunct (n, k, m + 1)
我究竟做错了什么?
一个功能
g a b c = 0
如果由三个值a
, b
和c
提供,则返回0
; 但是一个功能
g (a,b,c) = 0
如果由一个值(a,b,c)
提供,则返回0
。 这是价值的三倍 , a
, b
和c
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.