Search code examples
haskellrecursionprimitivefactorial

what does the term `fac` mean in Haskell?


What does the term fac mean in Haskell? I've seen it on many occasions but it appears to not have any definition of being of any type. I know it has something to do with factorials but am not quite sure what people mean when they refer to the term fac.

Here's an example:

sumFacs n = fac 0 + fac 1 + ... + fac (n-1) + fac n

Solution

  • Usually fac refers to the factorial function, which can be defined as:

    fac :: Int -> Int
    fac 0 = 1
    fac n = n * fac (n - 1)
    

    Of course, there are many different ways to define factorial in Haskell.