summaryrefslogtreecommitdiffstats
path: root/ex69.hs
blob: 04596be2d3ffd7f7c006c54242e99adaa4d5592e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- compute length of list


listlen :: [a] -> Int
listlen2 :: [a] -> Int -> Int

listlen ( x:xs )    = listlen2 xs 1
listlen2 ( x:xs ) n = listlen2 xs (n + 1)
listlen2 [] n       = n

myReverse (x:xs)  = myReverse xs ++ [x]
myReverse []      = []

makePalin x       = x ++ myReverse x

isPalin a         = a == myReverse a



-- in python: ",".join(["abc", "def"])
join :: String -> [String] -> String

join sep (x:xs)  | xs /= [] = x ++ sep ++ join sep xs
join sep [x]       = x


-- a tree

data Tree a = Node a (Tree a) (Tree a)
            | Empty
              deriving Show

--height :: Tree -> Int

height (Node _ left right)   =  max ((height left) + 1) ((height right) + 1)
height Empty = 0