Copyright | Copyright (C) 2021 Yoo Chung |
---|---|

License | GPL-3.0-or-later |

Maintainer | dev@chungyc.org |

Safe Haskell | Safe-Inferred |

Language | GHC2021 |

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P54.

# Documentation

A binary tree.

A `Tree`

of type `a`

consists of either an `Empty`

node,
or a `Branch`

containing one value of type `a`

with exactly two subtrees of type `a`

.

### Notes

This is not the problem 54A from the original Ninety-Nine Haskell Problems.
As it also mentions, there is nothing to do here except making sure code
compiles correctly, thanks to Haskell's strict typing and the way `Tree`

is defined.

Instead, the problem was replaced by the simple problems of implementing given binary trees as Haskell values. I.e., turn the examples from the original problem into simple problems to solve.

#### Instances

Generic (Tree a) Source # | |

Show a => Show (Tree a) Source # | |

NFData a => NFData (Tree a) Source # | |

Defined in Problems.BinaryTrees | |

Eq a => Eq (Tree a) Source # | |

Ord a => Ord (Tree a) Source # | An arbitrary total ordering for Defines an order for a set of |

type Rep (Tree a) Source # | |

Defined in Problems.BinaryTrees type Rep (Tree a) = D1 ('MetaData "Tree" "Problems.BinaryTrees" "ninetynine-1.3.0-4Xxr3hBGtJH9Ff8qb2Invo" 'False) (C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Branch" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Tree a)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Tree a))))) |

Define a shorthand function for constructing a leaf node.

A leaf node in `Tree`

is a branch with two empty subtrees.

Define as a binary tree consisting of only a single root node with value `'a'`

.