ninetynine-1.3.0: Ninety-Nine Haskell Problems
Copyright Copyright (C) 2021 Yoo Chung GPL-3.0-or-later dev@chungyc.org Safe-Inferred GHC2021

Problems.P54

Description

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

Synopsis

# Documentation

data Tree a Source #

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

Expand

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

Instances details
 Generic (Tree a) Source # Instance detailsDefined in Problems.BinaryTrees Associated Typestype Rep (Tree a) :: Type -> Type # Methodsfrom :: Tree a -> Rep (Tree a) x #to :: Rep (Tree a) x -> Tree a # Show a => Show (Tree a) Source # Instance detailsDefined in Problems.BinaryTrees MethodsshowsPrec :: Int -> Tree a -> ShowS #show :: Tree a -> String #showList :: [Tree a] -> ShowS # NFData a => NFData (Tree a) Source # Instance detailsDefined in Problems.BinaryTrees Methodsrnf :: Tree a -> () # Eq a => Eq (Tree a) Source # Instance detailsDefined in Problems.BinaryTrees Methods(==) :: Tree a -> Tree a -> Bool #(/=) :: Tree a -> Tree a -> Bool # Ord a => Ord (Tree a) Source # An arbitrary total ordering for Tree.Defines an order for a set of Trees. Not intended to support solving problems. Instance detailsDefined in Problems.BinaryTrees Methodscompare :: Tree a -> Tree a -> Ordering #(<) :: Tree a -> Tree a -> Bool #(<=) :: Tree a -> Tree a -> Bool #(>) :: Tree a -> Tree a -> Bool #(>=) :: Tree a -> Tree a -> Bool #max :: Tree a -> Tree a -> Tree a #min :: Tree a -> Tree a -> Tree a # type Rep (Tree a) Source # Instance detailsDefined 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)))))

leaf :: a -> Tree a Source #

Define a shorthand function for constructing a leaf node.

A leaf node in Tree is a branch with two empty subtrees.

Define as the tree as shown in the following.

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

Define as an empty binary tree.

Define as the following tree with integer values.