tree-traversals-0.1.2.0: Functions and newtype wrappers for traversing Trees
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Monoid.TreeDiagram

Description

Tools for working with the TreeDiagram monoid to draw tree diagrams.

Synopsis

Documentation

data TreeDiagram Source #

A monoid for generating tree diagrams

Instances

Instances details
Monoid TreeDiagram Source #

mempty is the empty tree diagram

>>> printTreeDiagram mempty

>>> printTreeDiagram $ mempty <> singleton 'a' <> mempty
'a'
Instance details

Defined in Data.Monoid.TreeDiagram

Semigroup TreeDiagram Source #

<> composes two tree diagrams horizontally, connecting them via horizontal line

>>> printTreeDiagram $ singleton 'a' <> singleton 'b'
'a'─'b'
Instance details

Defined in Data.Monoid.TreeDiagram

showTreeDiagram :: TreeDiagram -> ShowS Source #

render a tree diagram as a function that prepends a multi-line string

printTreeDiagram :: TreeDiagram -> IO () Source #

print a tree diagram

singleton :: Show a => a -> TreeDiagram Source #

draw a value as a simple, single-line tree diagram

>>> printTreeDiagram $ singleton 'a'
'a'

subtree :: TreeDiagram -> TreeDiagram Source #

Move a tree diagram to the subtree level, dropping a line down from the graph line to connect it to the new toplevel.

>>> printTreeDiagram $ subtree (singleton 'a') <> singleton 'b' <> subtree (singleton 'c')
 ┌─'b'─┐
 │     │
'a'   'c'
>>> printTreeDiagram $ subtree mempty
╷
│
╵

width :: TreeDiagram -> Int Source #

Full width of a tree diagram

>>> let d = singleton 'a' <> subtree (subtree (singleton 'b') <> singleton 'c')
>>> printTreeDiagram d
'a'───┐
      │
    ┌─'c'
    │
   'b'
>>> width d
9

height :: TreeDiagram -> Int Source #

Full height of a tree diagram

>>> let d = singleton 'a' <> subtree (subtree (singleton 'b') <> singleton 'c')
>>> printTreeDiagram d
'a'───┐
      │
    ┌─'c'
    │
   'b'
>>> height d
5