-1

正しくコンパイルされますが、動作しません。

それは機能し[]ますが、それ以外の場合は永遠にハングアップします。test1- わかりました、test 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)
4

1 に答える 1

4

無限ループがあります

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' ...
于 2012-11-13T19:00:29.907 に答える