Hours of hacking await! If I break, you can: 1. Restart: M-x haskell-process-restart 2. Configure logging: C-h v haskell-process-log (useful for debugging) 3. General config: M-x customize-mode 4. Hide these tips: C-h v haskell-process-show-debug-tips Changed directory: /home/hugo/Academic/Teaching/_Atual/Teoria de Categorias/Aulas/ λ> S $ S Zero S (S Zero) λ> :t produto produto :: Natural -> Natural -> Natural λ> fatorial $ S $ S $ S $ S Zero S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S (S Zero))))))))))))))))))))))) λ> paraInteiro $ fatorial $ S $ S $ S $ S Zero 24 λ> arv1 Raiz 10 Folha (Raiz 4 Folha Folha) Aula10.hs:35:20-24: error: [GHC-88464] … Variable not in scope: arv1i :: ArvBin Integer Suggested fix: Perhaps use `arv1' (line 32) | λ> arv2 Raiz 0 (Raiz 10 Folha (Raiz 4 Folha Folha)) (Raiz 10 Folha (Raiz 4 Folha Folha)) Aula10.hs:39:49-52: error: [GHC-39999] … * No instance for `Show a' arising from a use of `show' Possible fix: add (Show a) to the context of the type signature for: desenhaArvore :: forall a. ArvBin a -> String * In the first argument of `(++)', namely `(show x)' In the expression: (show x) ++ "\n" ++ desenhaArvore (subarv_esq) ++ desenhaArvore (subarv_dir) In an equation for `desenhaArvore': desenhaArvore (Raiz x subarv_esq subarv_dir) = (show x) ++ "\n" ++ desenhaArvore (subarv_esq) ++ desenhaArvore (subarv_dir) | λ> desenhaArvore arv1 "10\n.4\n.." λ> :t putStr putStr :: String -> IO () λ> putStr $ desenhaArvore arv1 10 .4 ..λ> putStr $ desenhaArvore arv1 10 . 4 . .λ> putStr $ desenhaArvore arv1 10 . 4 . .λ> putStr $ desenhaArvore arv1 :97:10-27: error: [GHC-83865] * Couldn't match type: Integer -> String with: [Char] Expected: String Actual: Integer -> String * In the second argument of `($)', namely `desenhaArvore arv1' In the expression: putStr $ desenhaArvore arv1 In an equation for `it': it = putStr $ desenhaArvore arv1 λ> putStr $ desenhaArvore arv1 :98:10-27: error: [GHC-83865] * Couldn't match type: Integer -> String with: [Char] Expected: String Actual: Integer -> String * In the second argument of `($)', namely `desenhaArvore arv1' In the expression: putStr $ desenhaArvore arv1 In an equation for `it': it = putStr $ desenhaArvore arv1 λ> putStr $ desenhaArvore arv1 0 10 . 4 . .λ> putStr $ desenhaArvore arv1 0 10 . 4 . . λ> putStr $ desenhaArvore arv1 0 10 . 4 . . λ> putStr $ desenhaArvore arv2 0 0 10 . 4 . . 10 . 4 . . λ> :t ArvBin :1:1-6: error: [GHC-31891] * Illegal term-level use of the type constructor or class `ArvBin' * defined at /home/hugo/Academic/Teaching/_Atual/Teoria de Categorias/Aulas/Aula10.hs:26:1 * In the expression: ArvBin λ> :i Arvbin :1:1-6: error: Not in scope: `Arvbin' λ> :i ArvBin type ArvBin :: * -> * data ArvBin a where Folha :: ArvBin a Raiz :: a -> ArvBin a -> ArvBin a -> ArvBin a -- Defined at /home/hugo/Academic/Teaching/_Atual/Teoria de Categorias/Aulas/Aula10.hs:26:1 instance Eq a => Eq (ArvBin a) -- Defined at /home/hugo/Academic/Teaching/_Atual/Teoria de Categorias/Aulas/Aula10.hs:29:19 instance Show a => Show (ArvBin a) -- Defined at /home/hugo/Academic/Teaching/_Atual/Teoria de Categorias/Aulas/Aula10.hs:29:13 λ> :i String type String :: * type String = [Char] -- Defined in `GHC.Base' λ> arv1 Raiz 10 Folha (Raiz 4 Folha Folha) λ> fmap (^2) arv1 Raiz 100 Folha (Raiz 16 Folha Folha) Aula10.hs:48:5-7: error: [GHC-54721] … `<$>' is not a (visible) method of class `Functor' | λ> (+15) <$> [1, 2, 3] [16,17,18] λ> :i Semigroup type Semigroup :: * -> Constraint class Semigroup a where (<>) :: a -> a -> a GHC.Base.sconcat :: GHC.Base.NonEmpty a -> a GHC.Base.stimes :: Integral b => b -> a -> a {-# MINIMAL (<>) | sconcat #-} -- Defined in `GHC.Base' instance Semigroup () -- Defined in `GHC.Base' instance (Semigroup a, Semigroup b) => Semigroup (a, b) -- Defined in `GHC.Base' instance (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) -- Defined in `GHC.Base' instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) -- Defined in `GHC.Base' instance (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) -- Defined in `GHC.Base' instance Semigroup b => Semigroup (a -> b) -- Defined in `GHC.Base' instance Semigroup a => Semigroup (IO a) -- Defined in `GHC.Base' instance Semigroup [a] -- Defined in `GHC.Base' instance Semigroup a => Semigroup (Maybe a) -- Defined in `GHC.Base' instance Semigroup Ordering -- Defined in `GHC.Base' instance Semigroup a => Semigroup (Solo a) -- Defined in `GHC.Base' instance Semigroup (Either a b) -- Defined in `Data.Either' λ> :i 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 ((,) a) -- Defined in `GHC.Base' instance Functor ((,,) a b) -- Defined in `GHC.Base' instance Functor ((,,,) a b c) -- Defined in `GHC.Base' instance Functor ((,,,,) a b c d) -- Defined in `GHC.Base' instance Functor ((,,,,,) a b c d e) -- Defined in `GHC.Base' instance Functor ((,,,,,,) a b c d e f) -- Defined in `GHC.Base' instance Functor ((->) r) -- Defined in `GHC.Base' instance Functor IO -- Defined in `GHC.Base' instance Functor [] -- Defined in `GHC.Base' instance Functor Maybe -- Defined in `GHC.Base' instance Functor Solo -- Defined in `GHC.Base' instance Functor (Either a) -- Defined in `Data.Either' λ> :i Monoid type Monoid :: * -> Constraint class Semigroup a => Monoid a where mempty :: a mappend :: a -> a -> a mconcat :: [a] -> a {-# MINIMAL mempty | mconcat #-} -- Defined in `GHC.Base' instance Monoid () -- Defined in `GHC.Base' instance (Monoid a, Monoid b) => Monoid (a, b) -- Defined in `GHC.Base' instance (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) -- Defined in `GHC.Base' instance (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) -- Defined in `GHC.Base' instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) -- Defined in `GHC.Base' instance Monoid b => Monoid (a -> b) -- Defined in `GHC.Base' instance Monoid a => Monoid (IO a) -- Defined in `GHC.Base' instance Monoid [a] -- Defined in `GHC.Base' instance Semigroup a => Monoid (Maybe a) -- Defined in `GHC.Base' instance Monoid Ordering -- Defined in `GHC.Base' instance Monoid a => Monoid (Solo a) -- Defined in `GHC.Base' Aula10.hs:58:10-23: error: [GHC-39999] … * No instance for `Semigroup Natural' arising from the superclasses of an instance declaration * In the instance declaration for `Monoid Natural' | λ> (S Zero) <> (S $ S Zero) S (S (S Zero)) λ> mempty :: Natural Zero λ> mconcat [Zero, S Zero, S (S (S (S Zero)))] S (S (S (S (S Zero)))) λ> :i 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 ((,) a) -- Defined in `Data.Foldable' instance Foldable (Either a) -- Defined in `Data.Foldable' instance Foldable [] -- Defined in `Data.Foldable' instance Foldable Maybe -- Defined in `Data.Foldable' instance Foldable Solo -- Defined in `Data.Foldable' λ> :i List :1:1-4: error: Not in scope: `List' λ> :i ([]) :1:2: error: [GHC-58481] parse error on input `[' λ> :i [] type List :: * -> * data List a = [] | a : [a] -- Defined in `GHC.Types' instance Traversable [] -- Defined in `Data.Traversable' instance MonadFail [] -- Defined in `Control.Monad.Fail' instance Foldable [] -- Defined in `Data.Foldable' instance Applicative [] -- Defined in `GHC.Base' instance Functor [] -- Defined in `GHC.Base' instance Monad [] -- Defined in `GHC.Base' instance Monoid [a] -- Defined in `GHC.Base' instance Semigroup [a] -- Defined in `GHC.Base' instance Ord a => Ord [a] -- Defined in `GHC.Classes' instance Read a => Read [a] -- Defined in `GHC.Read' instance Show a => Show [a] -- Defined in `GHC.Show' instance Eq a => Eq [a] -- Defined in `GHC.Classes' λ> meu_foldr (*) 12 [3, 5, 2] 360 λ> meu_foldl (*) 12 [3, 5, 2] 360 λ> meu_foldl_em_cauda (*) 12 [3, 5, 2] 360 λ> :i 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 ((,) a) -- Defined in `Data.Foldable' instance Foldable (Either a) -- Defined in `Data.Foldable' instance Foldable [] -- Defined in `Data.Foldable' instance Foldable Maybe -- Defined in `Data.Foldable' instance Foldable Solo -- Defined in `Data.Foldable' λ> :{ instance Foldable ArvBin where foldr _ x Folha = x foldr f x (Raiz r esq dir) =