poole@CPSC-M-POOLE01 haskell % ghci GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help ghci> head [] *** Exception: Prelude.head: empty list CallStack (from HasCallStack): error, called at libraries/base/GHC/List.hs:1646:3 in base:GHC.List errorEmptyList, called at libraries/base/GHC/List.hs:85:11 in base:GHC.List badHead, called at libraries/base/GHC/List.hs:81:28 in base:GHC.List head, called at :1:1 in interactive:Ghci1 ghci> :l BSTree [1 of 1] Compiling BSTree ( BSTree.hs, interpreted ) Ok, one module loaded. ghci> atree = Node 5 "alive" (Node 2 "be" Empty (Node 4 "fun" Empty Empty)) (Node 8 "food" Empty Empty) ghci> :type atree atree :: Num k => BSTree k String ghci> :l BSTree [1 of 1] Compiling BSTree ( BSTree.hs, interpreted ) Ok, one module loaded. ghci> :type ins ins :: Ord a => a -> t -> BSTree a t -> BSTree a t ghci> :info Ord type Ord :: * -> Constraint class Eq a => Ord a where compare :: a -> a -> Ordering (<) :: a -> a -> Bool (<=) :: a -> a -> Bool (>) :: a -> a -> Bool (>=) :: a -> a -> Bool max :: a -> a -> a min :: a -> a -> a {-# MINIMAL compare | (<=) #-} -- Defined in ‘GHC.Classes’ instance Ord Integer -- Defined in ‘GHC.Num.Integer’ instance Ord () -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c) => Ord (a, b, c) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Classes’ instance Ord Bool -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord a => Ord (Solo a) -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord a => Ord [a] -- Defined in ‘GHC.Classes’ instance (Ord a, Ord b) => Ord (Either a b) -- Defined in ‘Data.Either’ instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Maybe’ ghci> atree = Node 5 "alive" (Node 2 "be" Empty (Node 4 "fun" Empty Empty)) (Node 8 "food" Empty Empty) ghci> ins 6 "six" atree :9:1: error: • No instance for (Show (BSTree Integer String)) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it ghci> tolista (insert 6 "six" atree) [(2,"be"),(4,"fun"),(5,"alive"),(6,"six"),(8,"food")] ghci> :info Maybe type Maybe :: * -> * data Maybe a = Nothing | Just a -- Defined in ‘GHC.Maybe’ instance Traversable Maybe -- Defined in ‘Data.Traversable’ instance MonadFail Maybe -- Defined in ‘Control.Monad.Fail’ instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ instance Semigroup a => Semigroup (Maybe a) -- Defined in ‘GHC.Base’ instance Applicative Maybe -- Defined in ‘GHC.Base’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Monad Maybe -- Defined in ‘GHC.Base’ instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Maybe’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ ghci> :l BSTree [1 of 1] Compiling BSTree ( BSTree.hs, interpreted ) Ok, one module loaded. ghci> atree = Node 5 "alive" (Node 2 "be" Empty (Node 4 "fun" Empty Empty)) (Node 8 "food" Empty Empty) ghci> geval 4 atree :14:1: error: Variable not in scope: geval :: t0 -> BSTree k0 String -> t Suggested fix: Perhaps use ‘getval’ (line 69) ghci> getval 4 atree Just "fun" ghci> getval 17 atree Nothing ghci> :type getval 4 atree getval 4 atree :: Maybe String ghci> Leaving GHCi. poole@CPSC-M-POOLE01 haskell % ghci GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help ghci> :l BSTree [1 of 1] Compiling BSTree ( BSTree.hs, interpreted ) Ok, one module loaded. ghci> :type getval getval :: Ord t => t -> BSTree t a -> Maybe a ghci> :type show show :: Show a => a -> String ghci> :type readMaybe :1:1: error: Variable not in scope: readMaybe ghci> :type read read :: Read a => String -> a ghci> Leaving GHCi. poole@CPSC-M-POOLE01 haskell % ghci GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help ghci> :load BSTree2 [1 of 1] Compiling BSTree ( BSTree2.hs, interpreted ) Ok, one module loaded. ghci> :info BSTree type BSTree :: * -> * -> * data BSTree k v = Empty | Node k v (BSTree k v) (BSTree k v) -- Defined at BSTree2.hs:11:1 instance (Eq k, Eq v) => Eq (BSTree k v) -- Defined at BSTree2.hs:33:10 instance Foldable (BSTree k) -- Defined at BSTree2.hs:105:10 instance Functor (BSTree k) -- Defined at BSTree2.hs:94:10 instance (Read k, Read v) => Read (BSTree k v) -- Defined at BSTree2.hs:13:26 instance (Show k, Show v) => Show (BSTree k v) -- Defined at BSTree2.hs:13:20 ghci> :type map map :: (a -> b) -> [a] -> [b] ghci> :type fmap fmap :: Functor f => (a -> b) -> f a -> f b ghci> :info Functor type Functor :: (* -> *) -> Constraint class Functor f where fmap :: (a -> b) -> f a -> f b (<$) :: a -> f b -> f a {-# MINIMAL fmap #-} -- Defined in ‘GHC.Base’ instance Functor (BSTree k) -- Defined at BSTree2.hs:94:10 instance Functor ((,) a) -- Defined in ‘GHC.Base’ instance Functor ((,,) a b) -- Defined in ‘GHC.Base’ instance Functor ((,,,) a b c) -- Defined in ‘GHC.Base’ instance Functor ((->) r) -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Functor Solo -- Defined in ‘GHC.Base’ instance Functor [] -- Defined in ‘GHC.Base’ instance Functor (Either a) -- Defined in ‘Data.Either’ ghci> egtree Node 5 "alive" (Node 2 "be" Empty (Node 4 "fun" Empty Empty)) (Node 8 "food" Empty Empty) ghci> fmap ("not"++) egtree Node 5 "notalive" (Node 2 "notbe" Empty (Node 4 "notfun" Empty Empty)) (Node 8 "notfood" Empty Empty) ghci> fmap length egtree Node 5 5 (Node 2 2 Empty (Node 4 3 Empty Empty)) (Node 8 4 Empty Empty) ghci> :type fmap length egtree fmap length egtree :: BSTree Integer Int ghci> :type foldr foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b ghci> length egtree 4 ghci> :info Foldable type Foldable :: (* -> *) -> Constraint class Foldable t where Data.Foldable.fold :: Monoid m => t m -> m foldMap :: Monoid m => (a -> m) -> t a -> m Data.Foldable.foldMap' :: Monoid m => (a -> m) -> t a -> m foldr :: (a -> b -> b) -> b -> t a -> b Data.Foldable.foldr' :: (a -> b -> b) -> b -> t a -> b foldl :: (b -> a -> b) -> b -> t a -> b Data.Foldable.foldl' :: (b -> a -> b) -> b -> t a -> b foldr1 :: (a -> a -> a) -> t a -> a foldl1 :: (a -> a -> a) -> t a -> a Data.Foldable.toList :: t a -> [a] null :: t a -> Bool length :: t a -> Int elem :: Eq a => a -> t a -> Bool maximum :: Ord a => t a -> a minimum :: Ord a => t a -> a sum :: Num a => t a -> a product :: Num a => t a -> a {-# MINIMAL foldMap | foldr #-} -- Defined in ‘Data.Foldable’ instance Foldable (BSTree k) -- Defined at BSTree2.hs:105:10 instance Foldable ((,) a) -- Defined in ‘Data.Foldable’ instance Foldable (Either a) -- Defined in ‘Data.Foldable’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Foldable Solo -- Defined in ‘Data.Foldable’ instance Foldable [] -- Defined in ‘Data.Foldable’ ghci>