{- Module Fact contains the factorial functions from section 3 of the
   Notes on Functional Programming using Haskell.  See that section for a
   discussion and explanation of these examples.

   Author: H. Conrad Cunningham, Professor and Chair
           Computer and Information Science
           University of Mississippi
   Date:   3 September 2014  
-}

module Fact 
(fact1, fact2, fact3, fact4, fact6)
where

fact1 :: Int -> Int 
fact1 n = if n == 0 then 
              1 
          else
              n * fact1 (n-1)

fact2 :: Int -> Int 
fact2 n 
  | n == 0    = 1 
  | otherwise = n * fact2 (n-1)

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

fact4 :: Int -> Int 
fact4 n 
  | n == 0 =  1 
  | n >= 1 =  n * fact4 (n-1)

-- fact5 was valid for older Haskell standard, but not for Haskell
-- 2010.  (n+k) patterns were removed from the language.
-- fact5 :: Int -> Int 
-- fact5 0     = 1 
-- fact5 (n+1) = (n+1) * fact5 n

fact6 :: Int -> Int  
fact6 n = product [1..n]
