Prelude> :l c05.hs [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> *Main> *Main> *Main> f 45 f 45 46 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> Mon Mon :7:1: error: • No instance for (Show Dow) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :i Show :i Show type Show :: * -> Constraint class Show a where showsPrec :: Int -> a -> ShowS show :: a -> String showList :: [a] -> ShowS {-# MINIMAL showsPrec | show #-} -- Defined in ‘GHC.Show’ instance (Show a, Show b) => Show (Either a b) -- Defined in ‘Data.Either’ instance Show a => Show [a] -- Defined in ‘GHC.Show’ instance Show Word -- Defined in ‘GHC.Show’ instance Show GHC.Types.RuntimeRep -- Defined in ‘GHC.Show’ instance Show Ordering -- Defined in ‘GHC.Show’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ instance Show Integer -- Defined in ‘GHC.Show’ instance Show Int -- Defined in ‘GHC.Show’ instance Show Char -- Defined in ‘GHC.Show’ instance Show Bool -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c) => Show (a, b, c) -- Defined in ‘GHC.Show’ instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’ instance Show () -- Defined in ‘GHC.Show’ instance Show Float -- Defined in ‘GHC.Float’ instance Show Double -- Defined in ‘GHC.Float’ *Main> show [1, 2, 3] show [1, 2, 3] "[1,2,3]" *Main> :t (show [1, 2, 3]) :t (show [1, 2, 3]) (show [1, 2, 3]) :: String *Main> :t (show 123) :t (show 123) (show 123) :: String *Main> show 123 show 123 "123" *Main> show 'A' show 'A' "'A'" *Main> :i show :i show type Show :: * -> Constraint class Show a where ... show :: a -> String ... -- Defined in ‘GHC.Show’ *Main> :i Show :i Show type Show :: * -> Constraint class Show a where showsPrec :: Int -> a -> ShowS show :: a -> String showList :: [a] -> ShowS {-# MINIMAL showsPrec | show #-} -- Defined in ‘GHC.Show’ instance (Show a, Show b) => Show (Either a b) -- Defined in ‘Data.Either’ instance Show a => Show [a] -- Defined in ‘GHC.Show’ instance Show Word -- Defined in ‘GHC.Show’ instance Show GHC.Types.RuntimeRep -- Defined in ‘GHC.Show’ instance Show Ordering -- Defined in ‘GHC.Show’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ instance Show Integer -- Defined in ‘GHC.Show’ instance Show Int -- Defined in ‘GHC.Show’ instance Show Char -- Defined in ‘GHC.Show’ instance Show Bool -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) -- Defined in ‘GHC.Show’ instance (Show a, Show b, Show c) => Show (a, b, c) -- Defined in ‘GHC.Show’ instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’ instance Show () -- Defined in ‘GHC.Show’ instance Show Float -- Defined in ‘GHC.Float’ instance Show Double -- Defined in ‘GHC.Float’ *Main> :i Dow :i Dow type Dow :: * data Dow = Mon | Tue | Wed -- Defined at c05.hs:7:1 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :i Dow :i Dow type Dow :: * data Dow = Mon | Tue | Wed -- Defined at c05.hs:7:1 instance [safe] Show Dow -- Defined at c05.hs:7:37 *Main> show Mon show Mon "Mon" *Main> show Tue show Tue "Tue" *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> Mon Mon Luni *Main> show Mon show Mon "Luni" *Main> show "Luni" show "Luni" "\"Luni\"" *Main> :i Ord :i 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 a => Ord [a] -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Bool -- 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 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 (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 (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 (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 (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 (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 (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 (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 (a, b, c, d, e, f) -- 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 (a, b, c, d) -- 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 (a, b) -- Defined in ‘GHC.Classes’ instance Ord () -- 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’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :i Eq :i Eq type Eq :: * -> Constraint class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool {-# MINIMAL (==) | (/=) #-} -- Defined in ‘GHC.Classes’ instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Eq Word -- Defined in ‘GHC.Classes’ instance Eq Ordering -- Defined in ‘GHC.Classes’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Eq Float -- Defined in ‘GHC.Classes’ instance Eq Double -- Defined in ‘GHC.Classes’ instance Eq Char -- Defined in ‘GHC.Classes’ instance Eq Bool -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c) => Eq (a, b, c) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’ instance Eq () -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (Either a b) -- Defined in ‘Data.Either’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Eq Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> Mon == Mon Mon == Mon :27:1: error: • No instance for (Eq Dow) arising from a use of ‘==’ • In the expression: Mon == Mon In an equation for ‘it’: it = Mon == Mon *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> Mon == Mon Mon == Mon True *Main> Mon == Tue Mon == Tue False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> Succ (Succ Zero) Succ (Succ Zero) Succ (Succ Zero) *Main> Succ (Succ (Succ Zero)) Succ (Succ (Succ Zero)) Succ (Succ (Succ Zero)) *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> add (Succ (Succ Zero)) (Succ (Succ (Succ Zero))) ro))) Succ (Succ (Succ (Succ (Succ Zero)))) *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n3 == n3 n3 == n3 True *Main> n3 == n4 n3 == n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n4 n4 4 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n3 == n3 n3 == n3 :42:1: error: • No instance for (Eq Nat) arising from a use of ‘==’ • In the expression: n3 == n3 In an equation for ‘it’: it = n3 == n3 *Main> :i Eq :i Eq type Eq :: * -> Constraint class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool {-# MINIMAL (==) | (/=) #-} -- Defined in ‘GHC.Classes’ instance [safe] Eq Dow -- Defined at c05.hs:7:37 instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Eq Word -- Defined in ‘GHC.Classes’ instance Eq Ordering -- Defined in ‘GHC.Classes’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Eq Float -- Defined in ‘GHC.Classes’ instance Eq Double -- Defined in ‘GHC.Classes’ instance Eq Char -- Defined in ‘GHC.Classes’ instance Eq Bool -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c) => Eq (a, b, c) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’ instance Eq () -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (Either a b) -- Defined in ‘Data.Either’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Eq Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:45:3: error: ‘==’ is not a (visible) method of class ‘Show’ | 45 | (==) x y = (convert x) == (convert y) | ^^^^ c05.hs:46:3: error: ‘/=’ is not a (visible) method of class ‘Show’ | 46 | (/=) x y = (convert x) /= (convert y) | ^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n3 == n3 n3 == n3 True *Main> n3 == n1 n3 == n1 False *Main> n1 == n1 n1 == n1 True *Main> n2 == n2 n2 == n2 True *Main> n0 == n0 n0 == n0 True *Main> n0 == n3 n0 == n3 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0 /= n3 n0 /= n3 True *Main> n0 /= n1 n0 /= n1 True *Main> n0 /= n0 n0 /= n0 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0 /= n0 n0 /= n0 False *Main> n0 /= n1 n0 /= n1 True *Main> n0 /= n2 n0 /= n2 True *Main> n1 /= n2 n1 /= n2 True *Main> n2 /= n2 n2 /= n2 False *Main> :i Eq :i Eq type Eq :: * -> Constraint class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool {-# MINIMAL (==) | (/=) #-} -- Defined in ‘GHC.Classes’ instance [safe] Eq Nat -- Defined at c05.hs:44:10 instance [safe] Eq Dow -- Defined at c05.hs:7:37 instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Eq Word -- Defined in ‘GHC.Classes’ instance Eq Ordering -- Defined in ‘GHC.Classes’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Eq Float -- Defined in ‘GHC.Classes’ instance Eq Double -- Defined in ‘GHC.Classes’ instance Eq Char -- Defined in ‘GHC.Classes’ instance Eq Bool -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c) => Eq (a, b, c) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’ instance Eq () -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (Either a b) -- Defined in ‘Data.Either’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Eq Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n3 == n3 n3 == n3 True *Main> n3 == n1 n3 == n1 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:44:10: warning: [-Wmissing-methods] • No explicit implementation for either ‘==’ or ‘/=’ • In the instance declaration for ‘Eq Nat’ | 44 | instance Eq Nat where | ^^^^^^ Ok, one module loaded. *Main> n0 == n0 n0 == n0 *** Exception: stack overflow *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0 == n0 n0 == n0 True *Main> n0 == n1 n0 == n1 False *Main> n0 == n2 n0 == n2 False *Main> n0 /= n2 n0 /= n2 True *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:44:10: warning: [-Wmissing-methods] • No explicit implementation for either ‘==’ or ‘/=’ • In the instance declaration for ‘Eq Nat’ | 44 | instance Eq Nat where | ^^^^^^ Ok, one module loaded. *Main> n0 /= n2 n0 /= n2 *** Exception: stack overflow *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:44:10: warning: [-Wmissing-methods] • No explicit implementation for either ‘==’ or ‘/=’ • In the instance declaration for ‘Eq Nat’ | 44 | instance Eq Nat where | ^^^^^^ Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> egal n3 n3 egal n3 n3 :77:1: error: • No instance for (MyEq Nat) arising from a use of ‘egal’ • In the expression: egal n3 n3 In an equation for ‘it’: it = egal n3 n3 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:56:10: warning: [-Wmissing-methods] • No explicit implementation for ‘neegal’ • In the instance declaration for ‘MyEq Nat’ | 56 | instance MyEq Nat where | ^^^^^^^^ Ok, one module loaded. *Main> egal n3 n3 egal n3 n3 True *Main> egal n3 n4 egal n3 n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> neegal n3 n4 neegal n3 n4 True *Main> neegal n3 n3 neegal n3 n3 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> neegal n3 n3 neegal n3 n3 False *Main> neegal n3 n4 neegal n3 n4 True *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r Ok, one module loaded. *Main> neegal n3 n4 neegal n3 n4 True *Main> neegal n4 n4 neegal n4 n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> neegal n4 n4 neegal n4 n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> egal n4 n4 egal n4 n4 True *Main> egal n3 n4 egal n3 n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> egal n3 n4 egal n3 n4 False *Main> egal n4 n4 egal n4 n4 True *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> egal n4 n4 egal n4 n4 True *Main> neegal n4 n4 neegal n4 n4 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> neegal n4 n4 neegal n4 n4 *** Exception: stack overflow *Main> :i MyEq :i MyEq type MyEq :: * -> Constraint class MyEq a where egal :: a -> a -> Bool neegal :: a -> a -> Bool -- Defined at c05.hs:52:1 instance [safe] MyEq Nat -- Defined at c05.hs:58:10 *Main> :i Eq :i Eq type Eq :: * -> Constraint class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool {-# MINIMAL (==) | (/=) #-} -- Defined in ‘GHC.Classes’ instance [safe] Eq Nat -- Defined at c05.hs:44:10 instance [safe] Eq Dow -- Defined at c05.hs:7:37 instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Eq Word -- Defined in ‘GHC.Classes’ instance Eq Ordering -- Defined in ‘GHC.Classes’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Eq Float -- Defined in ‘GHC.Classes’ instance Eq Double -- Defined in ‘GHC.Classes’ instance Eq Char -- Defined in ‘GHC.Classes’ instance Eq Bool -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n, Eq o) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m, Eq n) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l, Eq m) => Eq (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k, Eq l) => Eq (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j, Eq k) => Eq (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i, Eq j) => Eq (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h, Eq i) => Eq (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g, Eq h) => Eq (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f, Eq g) => Eq (a, b, c, d, e, f, g) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e, Eq f) => Eq (a, b, c, d, e, f) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d, Eq e) => Eq (a, b, c, d, e) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b, Eq c) => Eq (a, b, c) -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’ instance Eq () -- Defined in ‘GHC.Classes’ instance (Eq a, Eq b) => Eq (Either a b) -- Defined in ‘Data.Either’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Eq Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:59:10: warning: [-Wmissing-methods] • No explicit implementation for either ‘egal’ or ‘neegal’ • In the instance declaration for ‘MyEq Nat’ | 59 | instance MyEq Nat where | ^^^^^^^^ Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:59:10: warning: [-Wmissing-methods] • No explicit implementation for either ‘egal’ or ‘neegal’ • In the instance declaration for ‘MyEq Nat’ | 59 | instance MyEq Nat where | ^^^^^^^^ Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> f 13 f 13 14 *Main> f f :112:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ (maybe you haven't applied a function to enough arguments?) • In a stmt of an interactive GHCi command: print it *Main> f == f f == f :113:1: error: • No instance for (Eq (Int -> Int)) arising from a use of ‘==’ (maybe you haven't applied a function to enough arguments?) • In the expression: f == f In an equation for ‘it’: it = f == f *Main> :i Ord :i 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 a => Ord [a] -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Bool -- 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 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 (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 (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 (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 (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 (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 (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 (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 (a, b, c, d, e, f) -- 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 (a, b, c, d) -- 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 (a, b) -- Defined in ‘GHC.Classes’ instance Ord () -- 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’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :i Ordering :i Ordering type Ordering :: * data Ordering = LT | EQ | GT -- Defined in ‘GHC.Types’ instance Eq Ordering -- Defined in ‘GHC.Classes’ instance Monoid Ordering -- Defined in ‘GHC.Base’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Semigroup Ordering -- Defined in ‘GHC.Base’ instance Enum Ordering -- Defined in ‘GHC.Enum’ instance Show Ordering -- Defined in ‘GHC.Show’ instance Read Ordering -- Defined in ‘GHC.Read’ instance Bounded Ordering -- Defined in ‘GHC.Enum’ *Main> :i Ord :i 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 a => Ord [a] -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Bool -- 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 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 (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 (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 (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 (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 (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 (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 (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 (a, b, c, d, e, f) -- 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 (a, b, c, d) -- 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 (a, b) -- Defined in ‘GHC.Classes’ instance Ord () -- 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’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:27:37: error: • No instance for (Eq Nat) arising from the 'deriving' clause of a data type declaration Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself • When deriving the instance for (Ord Nat) | 27 | data Nat = Zero | Succ Nat deriving Ord | ^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0 <= n1 n0 <= n1 True *Main> n0 <= n2 n0 <= n2 True *Main> n1 <= n2 n1 <= n2 True *Main> n1 <= n4 n1 <= n4 True *Main> n4 <= n1 n4 <= n1 False *Main> n4 <= n2 n4 <= n2 False *Main> n2 <= n2 n2 <= n2 True *Main> n2 < n2 n2 < n2 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:73:13: error: Multiple declarations of ‘Zero’ Declared at: c05.hs:27:12 c05.hs:73:13 | 73 | data Nat' = Zero | Succ Nat' deriving Ord | ^^^^ c05.hs:73:20: error: Multiple declarations of ‘Succ’ Declared at: c05.hs:27:19 c05.hs:73:20 | 73 | data Nat' = Zero | Succ Nat' deriving Ord | ^^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:73:41: error: • No instance for (Eq Nat') arising from the 'deriving' clause of a data type declaration Possible fix: use a standalone 'deriving instance' declaration, so you can specify the instance context yourself • When deriving the instance for (Ord Nat') | 73 | data Nat' = Zero' | Succ' Nat' deriving Ord | ^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0' <= n2' n0' <= n2' True *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> n0' <= n0' n0' <= n0' True *Main> n0' <= n1' n0' <= n1' False *Main> n0 <= n1 n0 <= n1 True *Main> Succ' Zero' < Zero' Succ' Zero' < Zero' True *Main> :i Ord :i 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 [safe] Ord Nat' -- Defined at c05.hs:73:46 instance [safe] Ord Nat -- Defined at c05.hs:27:37 instance Ord a => Ord [a] -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Bool -- 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 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 (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 (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 (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 (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 (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 (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 (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 (a, b, c, d, e, f) -- 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 (a, b, c, d) -- 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 (a, b) -- Defined in ‘GHC.Classes’ instance Ord () -- 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’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> Succ' Zero' < Zero' Succ' Zero' < Zero' False *Main> Zero' <= Zero' Zero' <= Zero' True *Main> Zero' <= Succ' Zero' Zero' <= Succ' Zero' True *Main> compare Zero' (Succ' Zero) compare Zero' (Succ' Zero) :143:22: error: • Couldn't match expected type ‘Nat'’ with actual type ‘Nat’ • In the first argument of ‘Succ'’, namely ‘Zero’ In the second argument of ‘compare’, namely ‘(Succ' Zero)’ In the expression: compare Zero' (Succ' Zero) *Main> compare Zero' (Succ' Zero') compare Zero' (Succ' Zero') LT *Main> compare (Succ' Zero') (Succ' Zero') compare (Succ' Zero') (Succ' Zero') EQ *Main> compare (Succ' (Succ' Zero')) (Succ' Zero') *Main> compare (Succ' (Succ' Zero')) (Succ' Zero') GT *Main> :i Ord :i 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 [safe] Ord Nat' -- Defined at c05.hs:81:10 instance [safe] Ord Nat -- Defined at c05.hs:27:37 instance Ord a => Ord [a] -- Defined in ‘GHC.Classes’ instance Ord Word -- Defined in ‘GHC.Classes’ instance Ord Ordering -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Ord Float -- Defined in ‘GHC.Classes’ instance Ord Double -- Defined in ‘GHC.Classes’ instance Ord Char -- Defined in ‘GHC.Classes’ instance Ord Bool -- 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 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 (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 (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 (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 (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 (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 (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 (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 (a, b, c, d, e, f) -- 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 (a, b, c, d) -- 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 (a, b) -- Defined in ‘GHC.Classes’ instance Ord () -- 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’ instance Ord Integer -- Defined in ‘integer-gmp-1.0.3.0:GHC.Integer.Type’ *Main> (Succ' (Succ' Zero')) > (Succ' Zero') (Succ' (Succ' Zero')) > (Succ' Zero') True *Main> "abc" == "abc" "abc" == "abc" True *Main> "abc" == "abcd" "abc" == "abcd" False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> i3 == i3 i3 == i3 True *Main> i3 == iminus3 i3 == iminus3 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r Ok, one module loaded. *Main> i0 == iminus0 i0 == iminus0 False *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> i0 == iminus0 i0 == iminus0 True *Main> i0 == i3 i0 == i3 False *Main> :t (+) :t (+) (+) :: Num a => a -> a -> a *Main> :i Num :i Num type Num :: * -> Constraint class Num a where (+) :: a -> a -> a (-) :: a -> a -> a (*) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -> a fromInteger :: Integer -> a {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-} -- Defined in ‘GHC.Num’ instance Num Word -- Defined in ‘GHC.Num’ instance Num Integer -- Defined in ‘GHC.Num’ instance Num Int -- Defined in ‘GHC.Num’ instance Num Float -- Defined in ‘GHC.Float’ instance Num Double -- Defined in ‘GHC.Float’ *Main> signum 10 signum 10 1 *Main> signum (-10) signum (-10) -1 *Main> signum 0 signum 0 0 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> sort [1, 2, 3, 6, 8, 4, 3, 2, 5, 6] 6] [1,2,2,3,3,4,5,6,6,8] *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:103:31: error: • No instance for (Ord a) arising from a use of ‘<=’ Possible fix: add (Ord a) to the context of the type signature for: sort :: forall a. [a] -> [a] • In the first argument of ‘filter’, namely ‘(<= hd)’ In the first argument of ‘sort’, namely ‘(filter (<= hd) tl)’ In the first argument of ‘(++)’, namely ‘(sort (filter (<= hd) tl))’ | 103 | sort (hd:tl) = (sort (filter (<=hd) tl)) ++ [hd] ++ (sort (filter (>hd) tl)) | ^^^^ Failed, no modules loaded. Prelude> :i (<=) :i (<=) type Ord :: * -> Constraint class Eq a => Ord a where ... (<=) :: a -> a -> Bool ... -- Defined in ‘GHC.Classes’ infix 4 <= Prelude> :t (<=) :t (<=) (<=) :: Ord a => a -> a -> Bool Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> sort [1, 2, 3, 6, 8, 4, 3, 2, 5, 6] 6] [1,2,2,3,3,4,5,6,6,8] *Main> sort [1, 2, 3, 6, 8, 4, 3, 2, 5, 6] 6] [1,2,2,3,3,4,5,6,6,8] *Main> sort ['A', 'Z', 'B'] sort ['A', 'Z', 'B'] "ABZ" *Main> :i Num :i Num type Num :: * -> Constraint class Num a where (+) :: a -> a -> a (-) :: a -> a -> a (*) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -> a fromInteger :: Integer -> a {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-} -- Defined in ‘GHC.Num’ instance Num Word -- Defined in ‘GHC.Num’ instance Num Integer -- Defined in ‘GHC.Num’ instance Num Int -- Defined in ‘GHC.Num’ instance Num Float -- Defined in ‘GHC.Float’ instance Num Double -- Defined in ‘GHC.Float’ *Main> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ *Main> :i Enum :i Enum type Enum :: * -> Constraint class Enum a where succ :: a -> a pred :: a -> a toEnum :: Int -> a fromEnum :: a -> Int enumFrom :: a -> [a] enumFromThen :: a -> a -> [a] enumFromTo :: a -> a -> [a] enumFromThenTo :: a -> a -> a -> [a] {-# MINIMAL toEnum, fromEnum #-} -- Defined in ‘GHC.Enum’ instance Enum Word -- Defined in ‘GHC.Enum’ instance Enum Ordering -- Defined in ‘GHC.Enum’ instance Enum Integer -- Defined in ‘GHC.Enum’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Enum Char -- Defined in ‘GHC.Enum’ instance Enum Bool -- Defined in ‘GHC.Enum’ instance Enum () -- Defined in ‘GHC.Enum’ instance Enum Float -- Defined in ‘GHC.Float’ instance Enum Double -- Defined in ‘GHC.Float’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:105:11: error: Multiple declarations of ‘Mon’ Declared at: c05.hs:9:12 c05.hs:105:11 | 105 | data Zi = Mon | Tue | Wed deriving Enum | ^^^ c05.hs:105:17: error: Multiple declarations of ‘Tue’ Declared at: c05.hs:9:18 c05.hs:105:17 | 105 | data Zi = Mon | Tue | Wed deriving Enum | ^^^ c05.hs:105:23: error: Multiple declarations of ‘Wed’ Declared at: c05.hs:9:24 c05.hs:105:23 | 105 | data Zi = Mon | Tue | Wed deriving Enum | ^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :i Enum :i Enum type Enum :: * -> Constraint class Enum a where succ :: a -> a pred :: a -> a toEnum :: Int -> a fromEnum :: a -> Int enumFrom :: a -> [a] enumFromThen :: a -> a -> [a] enumFromTo :: a -> a -> [a] enumFromThenTo :: a -> a -> a -> [a] {-# MINIMAL toEnum, fromEnum #-} -- Defined in ‘GHC.Enum’ instance [safe] Enum Zi -- Defined at c05.hs:105:36 instance Enum Word -- Defined in ‘GHC.Enum’ instance Enum Ordering -- Defined in ‘GHC.Enum’ instance Enum Integer -- Defined in ‘GHC.Enum’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Enum Char -- Defined in ‘GHC.Enum’ instance Enum Bool -- Defined in ‘GHC.Enum’ instance Enum () -- Defined in ‘GHC.Enum’ instance Enum Float -- Defined in ‘GHC.Float’ instance Enum Double -- Defined in ‘GHC.Float’ *Main> succ Lun succ Lun :182:1: error: • No instance for (Show Zi) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> succ Lun succ Lun Mar *Main> succ Mar succ Mar Mie *Main> succ Mie succ Mie *** Exception: succ{Zi}: tried to take `succ' of last tag in enumeration CallStack (from HasCallStack): error, called at c05.hs:105:43 in main:Main *Main> *Main> :i Enum :i Enum type Enum :: * -> Constraint class Enum a where succ :: a -> a pred :: a -> a toEnum :: Int -> a fromEnum :: a -> Int enumFrom :: a -> [a] enumFromThen :: a -> a -> [a] enumFromTo :: a -> a -> [a] enumFromThenTo :: a -> a -> a -> [a] {-# MINIMAL toEnum, fromEnum #-} -- Defined in ‘GHC.Enum’ instance [safe] Enum Zi -- Defined at c05.hs:105:43 instance Enum Word -- Defined in ‘GHC.Enum’ instance Enum Ordering -- Defined in ‘GHC.Enum’ instance Enum Integer -- Defined in ‘GHC.Enum’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Enum Char -- Defined in ‘GHC.Enum’ instance Enum Bool -- Defined in ‘GHC.Enum’ instance Enum () -- Defined in ‘GHC.Enum’ instance Enum Float -- Defined in ‘GHC.Float’ instance Enum Double -- Defined in ‘GHC.Float’ *Main> toEnum 0 toEnum 0 () *Main> (toEnum 0) :: Zi (toEnum 0) :: Zi Lun *Main> (toEnum 1) :: Zi (toEnum 1) :: Zi Mar *Main> (toEnum 2) :: Zi (toEnum 2) :: Zi Mie *Main> (toEnum 3) :: Zi (toEnum 3) :: Zi *** Exception: toEnum{Zi}: tag (3) is outside of enumeration's range (0,2) CallStack (from HasCallStack): error, called at c05.hs:105:43 in main:Main *Main> :i Enum :i Enum type Enum :: * -> Constraint class Enum a where succ :: a -> a pred :: a -> a toEnum :: Int -> a fromEnum :: a -> Int enumFrom :: a -> [a] enumFromThen :: a -> a -> [a] enumFromTo :: a -> a -> [a] enumFromThenTo :: a -> a -> a -> [a] {-# MINIMAL toEnum, fromEnum #-} -- Defined in ‘GHC.Enum’ instance [safe] Enum Zi -- Defined at c05.hs:105:43 instance Enum Word -- Defined in ‘GHC.Enum’ instance Enum Ordering -- Defined in ‘GHC.Enum’ instance Enum Integer -- Defined in ‘GHC.Enum’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Enum Char -- Defined in ‘GHC.Enum’ instance Enum Bool -- Defined in ‘GHC.Enum’ instance Enum () -- Defined in ‘GHC.Enum’ instance Enum Float -- Defined in ‘GHC.Float’ instance Enum Double -- Defined in ‘GHC.Float’ *Main> enumFrom Lun enumFrom Lun [Lun,Mar,Mie] *Main> enumFrom mar enumFrom mar :196:10: error: • Variable not in scope: mar • Perhaps you meant one of these: data constructor ‘Mar’ (line 105), ‘map’ (imported from Prelude), ‘max’ (imported from Prelude) *Main> enumFrom Mar enumFrom Mar [Mar,Mie] *Main> enumFromThen Lun Mar enumFromThen Lun Mar [Lun,Mar,Mie] *Main> enumFromThen Lun Mie enumFromThen Lun Mie [Lun,Mie] *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> enumFromThen Lun Mie enumFromThen Lun Mie [Lun,Mie,Vin,Dum] *Main> enumFromThen Lun Joi enumFromThen Lun Joi [Lun,Joi,Dum] *Main> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ *Main> :i Real :i Real type Real :: * -> Constraint class (Num a, Ord a) => Real a where toRational :: a -> Rational {-# MINIMAL toRational #-} -- Defined in ‘GHC.Real’ instance Real Word -- Defined in ‘GHC.Real’ instance Real Integer -- Defined in ‘GHC.Real’ instance Real Int -- Defined in ‘GHC.Real’ instance Real Float -- Defined in ‘GHC.Float’ instance Real Double -- Defined in ‘GHC.Float’ *Main> :i Rational :i Rational type Rational :: * type Rational = GHC.Real.Ratio Integer -- Defined in ‘GHC.Real’ *Main> toRational 3 toRational 3 3 % 1 *Main> toRational 5 toRational 5 5 % 1 *Main> 5 % 2 5 % 2 :208:3: error: Variable not in scope: (%) :: t0 -> t1 -> t *Main> (5 % 2) (5 % 2) :209:4: error: Variable not in scope: (%) :: t0 -> t1 -> t *Main> :i Rational :i Rational type Rational :: * type Rational = GHC.Real.Ratio Integer -- Defined in ‘GHC.Real’ *Main> :i Ratio :i Ratio :1:1: error: Not in scope: ‘Ratio’ *Main> :i GHC.Real.Ratio :i GHC.Real.Ratio type GHC.Real.Ratio :: * -> * data GHC.Real.Ratio a = !a GHC.Real.:% !a -- Defined in ‘GHC.Real’ instance Eq a => Eq (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => Ord (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => Enum (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => Fractional (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => Num (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => Real (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Integral a => RealFrac (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance Show a => Show (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ instance (Integral a, Read a) => Read (GHC.Real.Ratio a) -- Defined in ‘GHC.Read’ *Main> 10 GHC.Real.:% 2 10 GHC.Real.:% 2 10 % 2 *Main> 10 GHC.Real.:% 2 10 GHC.Real.:% 2 10 % 2 *Main> l.:% 3) 25 % 3 *Main> (9 GHC.Real.:% 2) + (10 GHC.Real.:% 3) .:% 3) 47 % 6 *Main> :i Rational :i Rational type Rational :: * type Rational = GHC.Real.Ratio Integer -- Defined in ‘GHC.Real’ *Main> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ *Main> :i Read :i Read type Read :: * -> Constraint class Read a where readsPrec :: Int -> ReadS a readList :: ReadS [a] GHC.Read.readPrec :: Text.ParserCombinators.ReadPrec.ReadPrec a GHC.Read.readListPrec :: Text.ParserCombinators.ReadPrec.ReadPrec [a] {-# MINIMAL readsPrec | readPrec #-} -- Defined in ‘GHC.Read’ instance Read a => Read [a] -- Defined in ‘GHC.Read’ instance Read Word -- Defined in ‘GHC.Read’ instance Read Ordering -- Defined in ‘GHC.Read’ instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’ instance Read Integer -- Defined in ‘GHC.Read’ instance Read Int -- Defined in ‘GHC.Read’ instance Read Float -- Defined in ‘GHC.Read’ instance Read Double -- Defined in ‘GHC.Read’ instance Read Char -- Defined in ‘GHC.Read’ instance Read Bool -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c, Read d) => Read (a, b, c, d) -- Defined in ‘GHC.Read’ instance (Read a, Read b, Read c) => Read (a, b, c) -- Defined in ‘GHC.Read’ instance (Read a, Read b) => Read (a, b) -- Defined in ‘GHC.Read’ instance Read () -- Defined in ‘GHC.Read’ instance (Read a, Read b) => Read (Either a b) -- Defined in ‘Data.Either’ *Main> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ *Main> :i Bounded :i Bounded type Bounded :: * -> Constraint class Bounded a where minBound :: a maxBound :: a {-# MINIMAL minBound, maxBound #-} -- Defined in ‘GHC.Enum’ instance Bounded Word -- Defined in ‘GHC.Enum’ instance Bounded Ordering -- Defined in ‘GHC.Enum’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Bounded Char -- Defined in ‘GHC.Enum’ instance Bounded Bool -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b) => Bounded (a, b) -- Defined in ‘GHC.Enum’ instance Bounded () -- Defined in ‘GHC.Enum’ *Main> minBound :: Int minBound :: Int -9223372036854775808 *Main> -2^63 -2^63 -9223372036854775808 *Main> maxBound :: Int maxBound :: Int 9223372036854775807 *Main> 2^63-1 2^63-1 9223372036854775807 *Main> minBound :: Integer minBound :: Integer :226:1: error: • No instance for (Bounded Integer) arising from a use of ‘minBound’ • In the expression: minBound :: Integer In an equation for ‘it’: it = minBound :: Integer *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> minBound :: Zi minBound :: Zi Lun *Main> maxBound :: Zi maxBound :: Zi Dum *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:73:46: error: • Can't make a derived instance of ‘Bounded Nat'’: ‘Nat'’ must be an enumeration type (an enumeration consists of one or more nullary, non-GADT constructors) or ‘Nat'’ must have precisely one constructor • In the data declaration for ‘Nat'’ | 73 | data Nat' = Succ' Nat' | Zero' deriving (Eq, Bounded) | ^^^^^^^ Failed, no modules loaded. Prelude> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ Prelude> :i Integral :i Integral type Integral :: * -> Constraint class (Real a, Enum a) => Integral a where quot :: a -> a -> a rem :: a -> a -> a div :: a -> a -> a mod :: a -> a -> a quotRem :: a -> a -> (a, a) divMod :: a -> a -> (a, a) toInteger :: a -> Integer {-# MINIMAL quotRem, toInteger #-} -- Defined in ‘GHC.Real’ instance Integral Word -- Defined in ‘GHC.Real’ instance Integral Integer -- Defined in ‘GHC.Real’ instance Integral Int -- Defined in ‘GHC.Real’ Prelude> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:111:1: error: parse error (possibly incorrect indentation or mismatched brackets) Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :i Unit :i Unit type Unit :: * data Unit = U -- Defined at c05.hs:110:1 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:112:1: error: Duplicate type signatures for ‘f’ at c05.hs:1:1 c05.hs:112:1 | 112 | f :: Unit -> Unit | ^ c05.hs:113:1: error: Multiple declarations of ‘f’ Declared at: c05.hs:2:1 c05.hs:113:1 | 113 | f _ = U | ^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> g U g U :239:1: error: • No instance for (Show Unit) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main>:r *Main> g U g U :241:1: error: • No instance for (Show Unit) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> g U g U U *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> g' 10 g' 10 U *Main> g' 0 g' 0 ^C ^C^CInterrupted. *Main> :i () :i () type () :: * data () = () -- Defined in ‘GHC.Tuple’ instance Eq () -- Defined in ‘GHC.Classes’ instance Monoid () -- Defined in ‘GHC.Base’ instance Ord () -- Defined in ‘GHC.Classes’ instance Semigroup () -- Defined in ‘GHC.Base’ instance Enum () -- Defined in ‘GHC.Enum’ instance Show () -- Defined in ‘GHC.Show’ instance Read () -- Defined in ‘GHC.Read’ instance Bounded () -- Defined in ‘GHC.Enum’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> h U h U :250:3: error: • Couldn't match expected type ‘()’ with actual type ‘Unit’ • In the first argument of ‘h’, namely ‘U’ In the expression: h U In an equation for ‘it’: it = h U *Main> h () h () () *Main> h' 10 h' 10 () *Main> h' 0 h' 0 ^C ^C^CInterrupted. *Main> :i () :i () type () :: * data () = () -- Defined in ‘GHC.Tuple’ instance Eq () -- Defined in ‘GHC.Classes’ instance Monoid () -- Defined in ‘GHC.Base’ instance Ord () -- Defined in ‘GHC.Classes’ instance Semigroup () -- Defined in ‘GHC.Base’ instance Enum () -- Defined in ‘GHC.Enum’ instance Show () -- Defined in ‘GHC.Show’ instance Read () -- Defined in ‘GHC.Read’ instance Bounded () -- Defined in ‘GHC.Enum’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :i Bounded :i Bounded type Bounded :: * -> Constraint class Bounded a where minBound :: a maxBound :: a {-# MINIMAL minBound, maxBound #-} -- Defined in ‘GHC.Enum’ instance [safe] Bounded Zi -- Defined at c05.hs:105:73 instance Bounded Word -- Defined in ‘GHC.Enum’ instance Bounded Ordering -- Defined in ‘GHC.Enum’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Bounded Char -- Defined in ‘GHC.Enum’ instance Bounded Bool -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) -- Defined in ‘GHC.Enum’ instance (Bounded a, Bounded b) => Bounded (a, b) -- Defined in ‘GHC.Enum’ instance Bounded () -- Defined in ‘GHC.Enum’ *Main> :i Int :i Int type Int :: * data Int = GHC.Types.I# GHC.Prim.Int# -- Defined in ‘GHC.Types’ instance Eq Int -- Defined in ‘GHC.Classes’ instance Ord Int -- Defined in ‘GHC.Classes’ instance Enum Int -- Defined in ‘GHC.Enum’ instance Num Int -- Defined in ‘GHC.Num’ instance Real Int -- Defined in ‘GHC.Real’ instance Show Int -- Defined in ‘GHC.Show’ instance Read Int -- Defined in ‘GHC.Read’ instance Bounded Int -- Defined in ‘GHC.Enum’ instance Integral Int -- Defined in ‘GHC.Real’ *Main> :i Bool :i Bool type Bool :: * data Bool = False | True -- Defined in ‘GHC.Types’ instance Eq Bool -- Defined in ‘GHC.Classes’ instance Ord Bool -- Defined in ‘GHC.Classes’ instance Enum Bool -- Defined in ‘GHC.Enum’ instance Show Bool -- Defined in ‘GHC.Show’ instance Read Bool -- Defined in ‘GHC.Read’ instance Bounded Bool -- Defined in ‘GHC.Enum’ *Main> :i [Int] :i [Int] :1:2: error: parse error on input ‘Int’ *Main> :i String :i String type String :: * type String = [Char] -- Defined in ‘GHC.Base’ *Main> :i Maybe :i Maybe type Maybe :: * -> * data Maybe a = Nothing | Just a -- Defined in ‘GHC.Maybe’ instance Applicative Maybe -- Defined in ‘GHC.Base’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Monad Maybe -- Defined in ‘GHC.Base’ instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Maybe’ instance Semigroup a => Semigroup (Maybe a) -- Defined in ‘GHC.Base’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ instance MonadFail Maybe -- Defined in ‘Control.Monad.Fail’ instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Traversable Maybe -- Defined in ‘Data.Traversable’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :i Maybe :i Maybe type Maybe :: * -> * data Maybe a = Nothing | Just a -- Defined in ‘GHC.Maybe’ instance Applicative Maybe -- Defined in ‘GHC.Base’ instance Eq a => Eq (Maybe a) -- Defined in ‘GHC.Maybe’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Monad Maybe -- Defined in ‘GHC.Base’ instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’ instance Ord a => Ord (Maybe a) -- Defined in ‘GHC.Maybe’ instance Semigroup a => Semigroup (Maybe a) -- Defined in ‘GHC.Base’ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ instance MonadFail Maybe -- Defined in ‘Control.Monad.Fail’ instance Read a => Read (Maybe a) -- Defined in ‘GHC.Read’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Traversable Maybe -- Defined in ‘Data.Traversable’ *Main> :i (Maybe Int) :i (Maybe Int) :1:2: error: parse error on input ‘Maybe’ *Main> :k (Maybe Int) :k (Maybe Int) (Maybe Int) :: * *Main> :k Int :k Int Int :: * *Main> :k Bool :k Bool Bool :: * *Main> :k (Maybe Int) :k (Maybe Int) (Maybe Int) :: * *Main> :k Maybe :k Maybe Maybe :: * -> * *Main> :kind Maybe :kind Maybe Maybe :: * -> * *Main> :i [] :i [] type [] :: * -> * data [] a = [] | a : [a] -- Defined in ‘GHC.Types’ instance Applicative [] -- Defined in ‘GHC.Base’ instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Functor [] -- Defined in ‘GHC.Base’ instance Monad [] -- Defined in ‘GHC.Base’ instance Monoid [a] -- Defined in ‘GHC.Base’ instance Ord a => Ord [a] -- Defined in ‘GHC.Classes’ instance Semigroup [a] -- Defined in ‘GHC.Base’ instance Show a => Show [a] -- Defined in ‘GHC.Show’ instance MonadFail [] -- Defined in ‘Control.Monad.Fail’ instance Read a => Read [a] -- Defined in ‘GHC.Read’ instance Foldable [] -- Defined in ‘Data.Foldable’ instance Traversable [] -- Defined in ‘Data.Traversable’ *Main> :i Either :i Either type Either :: * -> * -> * data Either a b = Left a | Right b -- Defined in ‘Data.Either’ instance Applicative (Either e) -- Defined in ‘Data.Either’ instance (Eq a, Eq b) => Eq (Either a b) -- Defined in ‘Data.Either’ instance Functor (Either a) -- Defined in ‘Data.Either’ instance Monad (Either e) -- Defined in ‘Data.Either’ instance (Ord a, Ord b) => Ord (Either a b) -- Defined in ‘Data.Either’ instance Semigroup (Either a b) -- Defined in ‘Data.Either’ instance (Show a, Show b) => Show (Either a b) -- Defined in ‘Data.Either’ instance (Read a, Read b) => Read (Either a b) -- Defined in ‘Data.Either’ instance Foldable (Either a) -- Defined in ‘Data.Foldable’ instance Traversable (Either a) -- Defined in ‘Data.Traversable’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> cmmdc (2 * 2 * 3 * 3 * 3) (2 * 3 * 3 * 5) cmmdc (2 * 2 * 3 * 3 * 3) (2 * 3 * 3 * 5) 18 *Main> cmmdc 0 0 cmmdc 0 0 0 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> cmmdc 0 0 cmmdc 0 0 :278:1: error: • No instance for (Show Exc) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> cmmdc 0 0 cmmdc 0 0 Left NotDefined *Main> impartire 10 0 impartire 10 0 Left DivByZero *Main> impartire 10 2 impartire 10 2 Right 5 *Main> cmmdc (2 * 2 * 3 * 3 * 3) (2 * 3 * 3 * 5) 3 * 5) Right 18 *Main> :i Functor :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 (Either a) -- Defined in ‘Data.Either’ instance Functor [] -- Defined in ‘GHC.Base’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Functor ((->) r) -- Defined in ‘GHC.Base’ instance Functor ((,,,) a b c) -- Defined in ‘GHC.Base’ instance Functor ((,,) a b) -- Defined in ‘GHC.Base’ instance Functor ((,) a) -- Defined in ‘GHC.Base’ *Main> :i fmap :i fmap type Functor :: (* -> *) -> Constraint class Functor f where fmap :: (a -> b) -> f a -> f b ... -- Defined in ‘GHC.Base’ *Main> :t fmap :t fmap fmap :: Functor f => (a -> b) -> f a -> f b *Main> :i [] :i [] type [] :: * -> * data [] a = [] | a : [a] -- Defined in ‘GHC.Types’ instance Applicative [] -- Defined in ‘GHC.Base’ instance Eq a => Eq [a] -- Defined in ‘GHC.Classes’ instance Functor [] -- Defined in ‘GHC.Base’ instance Monad [] -- Defined in ‘GHC.Base’ instance Monoid [a] -- Defined in ‘GHC.Base’ instance Ord a => Ord [a] -- Defined in ‘GHC.Classes’ instance Semigroup [a] -- Defined in ‘GHC.Base’ instance Show a => Show [a] -- Defined in ‘GHC.Show’ instance MonadFail [] -- Defined in ‘Control.Monad.Fail’ instance Read a => Read [a] -- Defined in ‘GHC.Read’ instance Foldable [] -- Defined in ‘Data.Foldable’ instance Traversable [] -- Defined in ‘Data.Traversable’ *Main> fmap (+1) [1,2,5] fmap (+1) [1,2,5] [2,3,6] *Main> fmap (+1) [1,2,5,8] fmap (+1) [1,2,5,8] [2,3,6,9] *Main> :i functor :i functor :1:1: error: Not in scope: ‘functor’ *Main> :i Functor :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 (Either a) -- Defined in ‘Data.Either’ instance Functor [] -- Defined in ‘GHC.Base’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Functor ((->) r) -- Defined in ‘GHC.Base’ instance Functor ((,,,) a b c) -- Defined in ‘GHC.Base’ instance Functor ((,,) a b) -- Defined in ‘GHC.Base’ instance Functor ((,) a) -- Defined in ‘GHC.Base’ *Main> fmap (+1) Nothing fmap (+1) Nothing Nothing *Main> fmap (+1) (Just 14) fmap (+1) (Just 14) Just 15 *Main> fmap (+1) (Left 14) fmap (+1) (Left 14) Left 14 *Main> fmap (+1) (Right 14) fmap (+1) (Right 14) Right 15 *Main> fmap (+1) (2, 3) fmap (+1) (2, 3) (2,4) *Main> fmap (+1) (2, 5, 3) fmap (+1) (2, 5, 3) (2,5,4) *Main> fmap (+1) (Left DivByZero) fmap (+1) (Left DivByZero) Left DivByZero *Main> fmap (+1) (Right DivByZero) fmap (+1) (Right DivByZero) :299:7: error: • No instance for (Num Exc) arising from a use of ‘+’ • In the first argument of ‘fmap’, namely ‘(+ 1)’ In the expression: fmap (+ 1) (Right DivByZero) In an equation for ‘it’: it = fmap (+ 1) (Right DivByZero) *Main> fmap (+5) (impartire 10 2) fmap (+5) (impartire 10 2) Right 10 *Main> fmap (+7) (impartire 10 2) fmap (+7) (impartire 10 2) Right 12 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r Ok, one module loaded. *Main> x x Right 12 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> x x Right 12 *Main> x' x' Right 12 *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :k Tree :k Tree Tree :: * -> * *Main> :i Functor :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 (Either a) -- Defined in ‘Data.Either’ instance Functor [] -- Defined in ‘GHC.Base’ instance Functor Maybe -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance Functor ((->) r) -- Defined in ‘GHC.Base’ instance Functor ((,,,) a b c) -- Defined in ‘GHC.Base’ instance Functor ((,,) a b) -- Defined in ‘GHC.Base’ instance Functor ((,) a) -- Defined in ‘GHC.Base’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> a2 a2 Node 5 (Node 10 Leaf Leaf) Leaf *Main> fmap (+1) a2 fmap (+1) a2 Node 6 (Node 11 Leaf Leaf) Leaf *Main> fmap (\x -> x `mod` 2 == 0) a2 *Main> fmap (\x -> x `mod` 2 == 0) a2 Node False (Node True Leaf Leaf) Leaf *Main> :i foldl :i foldl type Foldable :: (* -> *) -> Constraint class Foldable t where ... foldl :: (b -> a -> b) -> b -> t a -> b ... -- Defined in ‘Data.Foldable’ *Main> foldl (+) 0 [ 5, 6, 7 ] foldl (+) 0 [ 5, 6, 7 ] 18 *Main> :i Foldable :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 [] -- Defined in ‘Data.Foldable’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Foldable (Either a) -- Defined in ‘Data.Foldable’ instance Foldable ((,) a) -- Defined in ‘Data.Foldable’ *Main> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) c05.hs:162:5: error: • Occurs check: cannot construct the infinite type: b ~ Tree a -> b • The function ‘foldr’ is applied to four arguments, but its type ‘(a -> b -> b) -> b -> (Tree a -> a) -> b’ has only three In the expression: foldr f x (f i (foldr f x l)) r In an equation for ‘foldr’: foldr f x (Node i l r) = foldr f x (f i (foldr f x l)) r • Relevant bindings include r :: Tree a (bound at c05.hs:161:23) l :: Tree a (bound at c05.hs:161:21) i :: a (bound at c05.hs:161:19) x :: b (bound at c05.hs:161:11) f :: a -> b -> b (bound at c05.hs:161:9) foldr :: (a -> b -> b) -> b -> Tree a -> b (bound at c05.hs:160:3) | 162 | foldr f x (f i (foldr f x l)) r | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c05.hs, interpreted ) Ok, one module loaded. *Main> a2 a2 Node 5 (Node 10 Leaf Leaf) Leaf *Main> foldr (+) 0 a2 foldr (+) 0 a2 15 *Main> foldr (+) 1 a2 foldr (+) 1 a2 16 *Main>