Accumulators in haskell

前端 未结 3 1401

In Haskell, if I write

 fac n = facRec n 1
   where facRec 0 acc = acc
         facRec n acc = facRec (n-1) (acc*n)

and compile it with GHC

3条回答
  •  無奈伤痛
    2020-12-15 13:57

    Your question isn't complete. I assume you mean GHC, and at least without optimizations the answer is "yes" because the worker function (facRec in the first or fac in the second) has an arity 2 compared to one and the assembly will reflect this. With optimizations or with JHC the answer is probably "no".

提交回复
热议问题