Skip to content

Instantly share code, notes, and snippets.

@gdeest
Created February 8, 2013 20:40
Show Gist options
  • Select an option

  • Save gdeest/4741760 to your computer and use it in GitHub Desktop.

Select an option

Save gdeest/4741760 to your computer and use it in GitHub Desktop.
data Tree a = Node a [Tree a]
| Leaf a
build :: Monad m => (a -> m [a]) -> a -> m (Tree a)
build get_sons a = do sons <- get_sons a
case sons of
[] -> return $ Leaf a
lst -> do trees <- sequence $ map (build get_sons) lst
return $ Node a trees
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment