-- Comp1100   Semester 1, 2006

-- Example list function definitions
-- Clem Baker-Finch

-- Since most of these functions are already defined in the Prelude,
-- don't import them to avoid ambiguity.

import Prelude hiding (replicate, head, tail, null, sum)

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

replicate :: Int -> a -> [a]
replicate 0 x  =  []
replicate n x  =  x : replicate (n-1) x

head :: [a] -> a
head (x:xs)  = x

tail :: [a] -> [a]
tail (x:xs)  = xs

null :: [a] -> Bool
null []      = True
null (x:xs)  = False

sum :: Num a => [a] -> a
sum []      = 0
sum (x:xs)  = x + sum xs

double :: Num a => [a] -> [a]
double []     = []
double (x:xs) = x*2 : double xs

