ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2023 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Solutions.P73

Description

Some solutions to Problems.P73 of Ninety-Nine Haskell Problems.

Synopsis

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.