计算递归调用-Haskell

时间:2019-12-12 12:52:06

标签: haskell

是否存在对扩展欧几里德算法函数进行递归调用计数的函数?

rechnerb :: Integer -> Integer -> (Integer,Integer,Integer)
rechnerb 0 b = (b, 0, 1)
rechnerb a b = let (g, x, y) = rechnerb (b `mod` a) a
           in (g, y - (b `div` a) * x, x)

1 个答案:

答案 0 :(得分:3)

您可能会喜欢

rechnerb :: Integer -> Integer -> Int -> ((Integer,Integer,Integer), Int)
rechnerb 0 b c = ((b, 0, 1), c)
rechnerb a b c = let ((g, x, y), cnt) = rechnerb (b `mod` a) a (c+1)
                 in ((g, y - (b `div` a) * x, x), cnt)

并致电;

λ> rechnerb 7 1100 1 -- last parameter is the initial value (call # 1)
((1,-157,1),3)       -- (1,-157,1) is the answer and 3 is the # of calls to rechnerb