aboutsummaryrefslogtreecommitdiff
path: root/ch03/3_b_4.hs
blob: a711085f0f57874fe8ae602d8f3f1540c1ff2b5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Turn a list into a palindrome, i.e. it should read the same both backwards
-- and forwards. For example, given the list [1,2,3], your function should
-- return [1,2,3,3,2,1].

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

-- ghci> :l 3_b_4.hs
-- [1 of 1] Compiling Main             ( 3_b_4.hs, interpreted )
-- Ok, one module loaded.
-- ghci> makePalindrome []
-- []
-- ghci> makePalindrome [1, 2, 3]
-- [1,2,3,3,2,1]