
tail1 :: [a] -> a
tail1 [] = error "Empty list"
tail1 (x:[]) = x
tail1 (x:xs) = tail1 xs  


lastButOne :: [a] -> a
lastButOne [] = error "Empty List"
lastButOne (x:[]) = error "Singleton list"
lastButOne(x:y:[]) =  x
lastButOne(x:xs) = lastButOne xs

	


getLength :: [a]  -> Int
getLength [] = 0
getLength (x:[]) = 1
getLength(x:xs) = 1 + getLength xs


rev :: [a] -> [a]
rev [] = []
rev (x:[]) =  [x]
rev (x:xs) =  (rev xs)  ++ [x]


isPalin :: (Eq a) => [a] -> Bool
isPalin(xs) = (xs == rev xs)

split :: [a] -> ([a], [a])
split myList = splitAt (((length myList) + 1) `div` 2) myList 

isPalin2 :: (Eq a) => [a] -> Bool
isPalin2 [] = True
isPalin2 (x:[]) =  True
isPalin2 (x:y:[]) = (x == y)
isPalin2 (xs) = False

compress :: (Eq a) => [a] -> [a]
compress [] = 	[]
compress  (x:[]) = [x]
compress (xs) = xs
 
main :: IO ()
main = 	do
	print (isPalin([1]))
	print (compress([1,1]))
	print (compress([1,2,2,3,4]))

