Haskell 我的递归挂起

Haskell 我的递归挂起,haskell,recursion,Haskell,Recursion,它编译正确,但不起作用 它适用于[],但如果它还有其他功能,它将永远挂起测试1-正常,测试2挂起 --Tests pour 'effectuerAchat'. test1 = effectuerAchat achat1_1 [] == ([],achat1_1) test2 = effectuerAchat achat1_1 [offre1_1_1_100] == ([(Commande "fournisseur1" "article1" 1 100)],Achat "article1" 0)

它编译正确,但不起作用

它适用于
[]
,但如果它还有其他功能,它将永远挂起<代码>测试1-正常,
测试2
挂起

--Tests pour 'effectuerAchat'.
test1 = effectuerAchat achat1_1 [] == ([],achat1_1)
test2 = effectuerAchat achat1_1 [offre1_1_1_100] == ([(Commande "fournisseur1" "article1" 1 100)],Achat "article1" 0)
这是代码

effectuerAchat a os = rfred a (offresPour a os) (achatQuantite(a)) []
   where rfred a os n lc = 
            if os == []|| n==0
            then (lc,(Achat (achatArticle(a)) n))
            else 
                 if n>=(offreQuantite(head(os)))
                 then let c= (Commande (offreFournisseur(head(os))) (achatArticle(a)) (offreQuantite(head(os))) (offrePrix(head(os))))
                          n= n-(offreQuantite(head(os)))
                          xs =  tail(os)
                      in  rfred a xs n (c:lc)
                 else let c= (Commande (offreFournisseur(head(os))) (achatArticle(a)) n (offrePrix(head(os))))
                          n= 0
                          xs =  tail(os) 
                      in  rfred a xs n (c:lc)

你有一个无限循环

let c= (Commande (offreFournisseur(head(os))) (achatArticle(a)) (offreQuantite(head(os))) (offrePrix(head(os))))
    n= n-(offreQuantite(head(os)))
    ^^^^^
右侧的
n
不是上面测试中的
n
,而是在装订左侧引入的
n
(从外部范围看,它会遮挡住)。如果
os(=offresPour achat1_1[offre1_1_1_100])
包含多个项目,则测试中需要
n

if os == []|| n==0
在递归调用中,计算挂起

以不同的方式命名变量

let c = ...
    n' = n - ...
in rfred ... n' ...

请为这个问题添加一些细节!“it”应该做什么?如果(1)添加一些关于代码应该做什么以及预期结果的信息,(2)包含数据声明(什么是
Achat
command
应该是?)和(3),您就更有可能得到有用的答复您可以用英语命名变量和函数。猜测一下:
offresPour
会创建一个无限列表,
n
永远不会到达
0
(可能是因为
offfrequantite
会返回零或负数)。谢谢Daniel!完全是我的错!现在一切都很好