Created
November 4, 2012 00:47
-
-
Save amalloy/4009630 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
treeSeq :: (a -> [a]) -> a -> [a] | |
treeSeq children root = root : concatMap (treeSeq children) (children root) | |
data Tree a = Leaf a | |
| Branch (Tree a) (Tree a) | |
deriving (Show, Eq) | |
children :: Tree a -> [Tree a] | |
children (Leaf a) = [] | |
children (Branch x y) = [x, y] | |
-- treeSeq children $ Branch (Leaf 1) (Branch (Leaf 2) (Leaf 3)) | |
-- [Branch (Leaf 1) (Branch (Leaf 2) (Leaf 3)), | |
-- Leaf 1, Branch (Leaf 2) (Leaf 3), Leaf 2, Leaf 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment