-- ([False,True],[’0’,’1’]) :: ([Bool], [Char]) -- [tail, init, reverse] :: [[a] -> [a]] palindrome :: [a] -> Bool palindrome xs = reverse xs == xs twice :: (a -> a) -> a -> a twice f x = f (f x) length' :: [a] -> Int length' [] = 0 length' (_:xs) = 1 + length xs {- Evaluate length [1,2,3] length [1,2,3] = 1 + length [2,3] = 1 + 1 + length [3] = 1 + 1 + 1 + length [] = 1 + 1 + 1 + 0 = 3 -} -- Define and using recursion and [] = True and (x:xs) = x && and xs sum100 :: Int sum100 = sum [x*x | x <- [1..100]] pyths :: Int -> [(Int, Int, Int)] pyths n = [(x,y,z)| x <- [1..n] , y <- [1..n] , z <- [1..n] , x^2 + y^2 == z^2] -- a) safetail :: [a] -> [a] safetail xs = if null xs then [] else tail xs -- b) safetail' :: [a] -> [a] safetail' xs | null xs = [] | otherwise = tail xs -- c) safetail'' :: [a] -> [a] safetail'' [] = [] safetail'' xs = tail xs -- or safetail''' :: [a] -> [a] safetail''' [] = [] safetail''' (_:xs) = xs