import Data.Char

-- Sniglet for a list of the natural numbers:

nat = [0,1,2] ++ map (+3) nat

-- collapse sequences of identical elements, e.g.,
--  uniq [1,2,3,3,3,6,5,6,5,5] = [1,2,3,6,5,6,5]
--  uniq "foobarbaaz" = "fobarbaz"

uniq :: (Eq a) => [a] -> [a]

uniq [] = []
uniq (x:[]) = [x]
uniq (x0:x1:xs) | (x0 == x1) = uniq (x1:xs)
uniq (x0:x1:xs) = x0:(uniq (x1:xs))

-- Goofing around with first-class functions

-- map (\f -> f 0.5) [sin,cos,(+1),(*2),(^2),sqrt]
-- map ($ 0.5) [sin,cos,(+1),(*2),(^2),sqrt]
-- zipWith ($) [sin,cos,(+1),(*2),(^2),sqrt] [0..]


-- interleaving merge of heterogeneous lists, using Either type
(++++) :: [a] -> [b] -> [Either a b]

(x:xs) ++++ (y:ys) = (Left x):(Right y):(xs++++ys)
[] ++++ ys = map Right ys
xs ++++ [] = map Left xs

-- use type class by wrapping string to make it case-insensitive for
-- equality testing

data CiS = CiS [Char] deriving Show

-- -- Just test if equal in first three characters
-- instance Eq CiS where
--   CiS xs == CiS ys    = (take 3 xs) == (take 3 ys)

instance Eq CiS where
  CiS xs == CiS ys  =  map toUpper xs == map toUpper ys

