Copyright | Copyright (C) 2023 Yoo Chung |
---|---|
License | GPL-3.0-or-later |
Maintainer | dev@chungyc.org |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Some solutions to Problems.P73 of Ninety-Nine Haskell Problems.
Synopsis
- treeToSexp :: MultiwayTree Char -> String
- sexpToTree :: String -> Maybe (MultiwayTree Char)
Documentation
treeToSexp :: MultiwayTree Char -> String Source #
An s-expression is
commonly represented as a list of items between parentheses.
In particular, s-expressions can be nested, e.g., (a b (c d) e (f g))
.
It is used by programming languages such as Lisp
and Scheme.
A possible way to represent a multiway tree with an s-expression is for the first element in a list to represent the root of the tree, and the rest of the elements in the list would be its children. As a special case, a multiway tree with no children is represented without parentheses.
Write a function which will return this s-expression representation of a multiway tree as a string.
sexpToTree :: String -> Maybe (MultiwayTree Char) Source #
Write a function which will convert an s-expression, representing
a multiway tree as in treeToSexp
, into a MultiwayTree
.