From 6edda3496a7cea4336df70b40c485c7628e48a6a Mon Sep 17 00:00:00 2001 From: Chris Done Date: Thu, 2 Jan 2025 16:09:15 +0000 Subject: [PATCH] Update examples --- docs/examples/index.html | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/examples/index.html b/docs/examples/index.html index 455b86f..c028a86 100644 --- a/docs/examples/index.html +++ b/docs/examples/index.html @@ -484,4 +484,26 @@

27-discussion-64.hell

main = do
   let myRecord = Main.MyRecord {sum = Main.MySumR}
   Text.putStrLn "hello world"
+

28-trees.hell

-- 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'
\ No newline at end of file