Tree datastructures: Difference between revisions

→‎{{header|Haskell}}: Added direct parsing of a tree representation (to the Data.Tree variant)
(→‎{{header|Haskell}}: Added a less instructive variant, using the pre-cooked Data.Tree)
(→‎{{header|Haskell}}: Added direct parsing of a tree representation (to the Data.Tree variant))
Line 489:
 
-------------------------- TESTS -------------------------
 
main :: IO ()
main = do
putStrLn "Tree representation parsed directly:\n"
putStrLn $ drawTree $ Node "" nativeForest
 
putStrLn "Trees from indented text:\n"
let trees =
Line 514 ⟶ 516:
" be",
" irregular"
]
 
nativeForest :: Forest String
nativeForest =
[ Node
{ rootLabel = "RosettaCode",
subForest =
[ Node
{ rootLabel = "rocks",
subForest =
[ Node
{ rootLabel = "code",
subForest = []
},
Node
{ rootLabel = "comparison",
subForest = []
},
Node
{ rootLabel = "wiki",
subForest = []
}
]
},
Node
{ rootLabel = "mocks",
subForest =
[ Node
{ rootLabel = "trolling",
subForest = []
}
]
}
]
},
Node
{ rootLabel = "Some lists",
subForest =
[ Node
{ rootLabel = "may",
subForest = []
},
Node {rootLabel = "be", subForest = []},
Node {rootLabel = "irregular", subForest = []}
]
}
]</lang>
{{Out}}
<pre>TreesTree fromrepresentation indentedparsed textdirectly:
 
|
+- RosettaCode
| |
| +- rocks
| | |
| | +- code
| | |
| | +- comparison
| | |
| | `- wiki
| |
| `- mocks
| |
| `- trolling
|
`- Some lists
|
+- may
|
+- be
|
`- irregular
 
Trees from indented text:
 
|
9,655

edits