{- Module FactInteger contains versions of the factorial functions
   from section 3 of the Notes on Functional Programming using
   Haskell. These versions use the unbounded integer type Integer
   Integer of the default host processor integer type Int.  See the 
   section of the Notes for a general discussion of these functions

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

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

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

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

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

fact4 :: Integer -> Integer 
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 :: Integer -> Integder 
-- fact5 0     = 1 
-- fact5 (n+1) = (n+1) * fact5 n

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