summaryrefslogtreecommitdiffstats
path: root/ex69.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ex69.hs')
-rw-r--r--ex69.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/ex69.hs b/ex69.hs
new file mode 100644
index 0000000..04596be
--- /dev/null
+++ b/ex69.hs
@@ -0,0 +1,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