Skip to content

Instantly share code, notes, and snippets.

@polgfred
Created April 29, 2010 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polgfred/383913 to your computer and use it in GitHub Desktop.
Save polgfred/383913 to your computer and use it in GitHub Desktop.
data Node t = Leaf t | Branch [(Node t)]
-- this is the emitter
emit :: Node Char -> [Char]
emit (Leaf c) = [c]
emit (Branch ns) = "(" ++ (concat (map emit ns)) ++ ")"
main = putStrLn (emit (Branch [
Leaf 'A',
Leaf 'B',
Leaf 'C',
Branch [
Leaf 'D',
Leaf 'E',
Branch [
Leaf 'F',
Leaf 'G',
Leaf 'H'
],
Leaf 'I'
],
Leaf 'J'
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment