4
Haskell是否具有尾递归优化?
我今天在Unix中发现了“ time”命令,以为我会用它来检查Haskell的尾递归函数与普通递归函数之间的运行时差异。 我编写了以下函数: --tail recursive fac :: (Integral a) => a -> a fac x = fac' x 1 where fac' 1 y = y fac' x y = fac' (x-1) (x*y) --normal recursive facSlow :: (Integral a) => a -> a facSlow 1 = 1 facSlow x = x …