Skip to content

Commit

Permalink
Add Tree example
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Jan 2, 2025
1 parent d81cc73 commit 0cf0283
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/28-trees.hell
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Basic example of a tree data structure.
main = do
let tree =
Tree.Node "1" [
Tree.Node "1.a" [],
Tree.Node "1.b" [
Tree.Node "1.b.x" []
]
]
-- Do a trivial map, include the length of the tag in the nodes.
let tree' = Tree.map (\a -> (a, Text.length a)) tree
-- Write the tree out in a Lisp syntax.
Tree.foldTree
(\(a, len) children -> do
Text.putStr "("
Text.putStr a
Text.putStr " "
Text.putStr $ Show.show len
Monad.forM_ children (\m -> do Text.putStr " "; m)
Text.putStr ")")
tree'

0 comments on commit 0cf0283

Please sign in to comment.