about summary refs log tree commit diff
path: root/universe/crack_the_coding_interview/to_tree.hs
diff options
context:
space:
mode:
Diffstat (limited to 'universe/crack_the_coding_interview/to_tree.hs')
-rw-r--r--universe/crack_the_coding_interview/to_tree.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/universe/crack_the_coding_interview/to_tree.hs b/universe/crack_the_coding_interview/to_tree.hs
new file mode 100644
index 000000000000..8496d88c0c0c
--- /dev/null
+++ b/universe/crack_the_coding_interview/to_tree.hs
@@ -0,0 +1,11 @@
+data Tree a = Node a [Tree a] deriving (Show)
+
+withRoot :: [a] -> [Tree a]
+withRoot xs = xs |> toThing |> fmap buildTree
+
+buildTree :: (a, [a])
+
+
+toTree :: [a] -> Tree a
+toTree [x]      = Node x []
+toTree [x | xs] = Node x (toTree xs)