module StdList where

emptyList :: [a]
emptyList = []

isEmpty :: [a] -> Bool
isEmpty [] = True
isEmpty _ = False

cons :: a -> [a] -> [a]
cons x list = x : list

head :: [a] -> a
head [] = error "Empty list"
head (x:_) = x

tail :: [a] -> [a]
tail [] = error "Empty list"
tail (_:xs) = xs

append :: [a] -> [a] -> [a]
append [] ys = ys
append (x:xs) ys = x : append xs ys

update :: [a] -> Int -> a -> [a]
update [] _ _ = error "Empty list"
update (_:xs) 0 y = y : xs
update (x:xs) i y = x : update xs (i - 1) y

-- | Compute suffixes of a list
--
-- Examples:
--
-- >>> suffixes [1,2,3,4]
-- [[1,2,3,4],[2,3,4],[3,4],[4],[]]
--
-- >>> suffixes []
-- [[]]
suffixes :: [a] -> [[a]]
suffixes [] = [[]]
suffixes (x:xs) = (x:xs) : suffixes xs
