about summary refs log tree commit diff
path: root/users/wpcarro/scratch/crack_the_coding_interview/to_tree.hs
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/scratch/crack_the_coding_interview/to_tree.hs')
-rw-r--r--users/wpcarro/scratch/crack_the_coding_interview/to_tree.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/users/wpcarro/scratch/crack_the_coding_interview/to_tree.hs b/users/wpcarro/scratch/crack_the_coding_interview/to_tree.hs
new file mode 100644
index 0000000000..8496d88c0c
--- /dev/null
+++ b/users/wpcarro/scratch/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)