diff options
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.hs | 11 |
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 000000000000..8496d88c0c0c --- /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) |