stefan@stefans-MacBook-Pro curs4 % ghci ghci GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help Prelude> :r :r Ok, no modules loaded. Prelude> :l curs4 :l curs4 [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f 3 4 f 3 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f3 17 f3 17 20 *Main> f3 20 f3 20 23 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f5 20 f5 20 25 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f3 20 f3 20 23 *Main> f5 20 f5 20 25 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :type f :type f f :: Int -> Int -> Int *Main> :type adder :type adder adder :: Int -> Int -> Int *Main> :Lr :Lr unknown command ':Lr' use :? for help. *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f 2 3 f 2 3 5 *Main> f 3 4 f 3 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f3' 10 f3' 10 13 *Main> f3' 17 f3' 17 20 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f 3 4 f 3 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f 3 4 f 3 4 7 *Main> (f 3) 4 (f 3) 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> sum3 3 4 5 sum3 3 4 5 12 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> sum3 3 4 5 sum3 3 4 5 12 *Main> ((sum3 3) 4) 5 ((sum3 3) 4) 5 12 *Main> :t (sum3 3) :t (sum3 3) (sum3 3) :: Int -> Int -> Int *Main> :t ((sum3 3) 4) :t ((sum3 3) 4) ((sum3 3) 4) :: Int -> Int *Main> sum3 3 sum3 3 :36:1: error: • No instance for (Show (Int -> 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> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f' 3 4 f' 3 4 7 *Main> f'' 3 4 f'' 3 4 7 *Main> f 3 4 f 3 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) curs4.hs:25:1: error: Duplicate type signatures for ‘f''’ at curs4.hs:22:1-3 curs4.hs:25:1-3 | 25 | f'' :: Int -> (Int -> Int) | ^^^ curs4.hs:26:1: error: Multiple declarations of ‘f''’ Declared at: curs4.hs:23:1 curs4.hs:26:1 | 26 | f'' = \x y -> x + y | ^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f''' 3 4 f''' 3 4 7 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> mistery f5 mistery f5 12 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> mistery double mistery double 14 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> (\x -> x + x) 7 (\x -> x + x) 7 14 *Main> (\x -> x * 3) 7 (\x -> x * 3) 7 21 *Main> (\x -> x * 3) 7 (\x -> x * 3) 7 21 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> comp double f3 7 comp double f3 7 20 *Main> comp f3 double 7 comp f3 double 7 17 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f3double 7 f3double 7 17 *Main> doublef3 7 doublef3 7 20 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :t (.) :t (.) (.) :: (b -> c) -> (a -> b) -> a -> c *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> f3double' 7 f3double' 7 17 *Main> doublef3' 7 doublef3' 7 20 *Main> f3double 7 f3double 7 17 *Main> ((.) f3 double) 7 ((.) f3 double) 7 17 *Main> ((.) double f3) 7 ((.) double f3) 7 20 *Main> :info (.) :info (.) (.) :: (b -> c) -> (a -> b) -> a -> c -- Defined in ‘GHC.Base’ infixr 9 . *Main> (double . f3) 7 (double . f3) 7 20 *Main> (f3 . double) 7 (f3 . double) 7 17 *Main> (+) 3 4 (+) 3 4 7 *Main> 3 + 4 3 + 4 7 *Main> :t ($) :t ($) ($) :: (a -> b) -> a -> b *Main> :info ($) :info ($) ($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’ infixr 0 $ *Main> double 3 double 3 6 *Main> double $ 3 double $ 3 6 *Main> (f3 . double) 7 (f3 . double) 7 17 *Main> (f3 . double) $ 7 (f3 . double) $ 7 17 *Main> f3 . double $ 7 f3 . double $ 7 17 *Main> f3 . double 7 f3 . double 7 :79:6: error: • Couldn't match expected type ‘a -> Int’ with actual type ‘Int’ • Possible cause: ‘double’ is applied to too many arguments In the second argument of ‘(.)’, namely ‘double 7’ In the expression: f3 . double 7 In an equation for ‘it’: it = f3 . double 7 • Relevant bindings include it :: a -> Int (bound at :79:1) *Main> f3 . (double 7) f3 . (double 7) :80:7: error: • Couldn't match expected type ‘a -> Int’ with actual type ‘Int’ • Possible cause: ‘double’ is applied to too many arguments In the second argument of ‘(.)’, namely ‘(double 7)’ In the expression: f3 . (double 7) In an equation for ‘it’: it = f3 . (double 7) • Relevant bindings include it :: a -> Int (bound at :80:1) *Main> f3 . double $ 7 f3 . double $ 7 17 *Main> :t ($) :t ($) ($) :: (a -> b) -> a -> b *Main> :t map :t map map :: (a -> b) -> [a] -> [b] *Main> map double [ 1, 2, 3 ] map double [ 1, 2, 3 ] [2,4,6] *Main> map f5 [ 1, 2, 3 ] map f5 [ 1, 2, 3 ] [6,7,8] *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> map' f5 [ 1, 2, 3 ] map' f5 [ 1, 2, 3 ] [6,7,8] *Main> map' double [ 1, 2, 3 ] map' double [ 1, 2, 3 ] [2,4,6] *Main> [ double, f5, f3 ] [ double, f5, f3 ] :89: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> length [ double, f5, f3 ] length [ double, f5, f3 ] 3 *Main> (head ([ double, f5, f3 ])) 5 (head ([ double, f5, f3 ])) 5 10 *Main> (head ([ double, f5, f3 ])) 5 (head ([ double, f5, f3 ])) 5 10 *Main> map' (\f -> f 3) [ double, f5, f3 ] map' (\f -> f 3) [ double, f5, f3 ] [6,8,6] *Main> :t filter :t filter filter :: (a -> Bool) -> [a] -> [a] *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) curs4.hs:136:12: error: • Couldn't match expected type ‘(a0 -> a0 -> a0) -> t0 -> a1’ with actual type ‘Int’ • The function ‘x’ is applied to two arguments, but its type ‘Int’ has none In the first argument of ‘(==)’, namely ‘x mod 2’ In the expression: x mod 2 == 0 | 136 | iseven x = x mod 2 == 0 | ^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> iseven 7 iseven 7 False *Main> iseven 6 iseven 6 True *Main> filter iseven [3,4,5,7,8,12,13,14] filter iseven [3,4,5,7,8,12,13,14] [4,8,12,14] *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> filter' iseven [3,4,5,7,8,12,13,14] filter' iseven [3,4,5,7,8,12,13,14] [4,8,12,14] *Main> filter' (\x -> x mod 3 == 0) [3,4,5,7,8,12,13,14] filter' (\x -> x mod 3 == 0) [3,4,5,7,8,12,13,14] :102:1: error: • Non type-variable argument in the constraint: Num ((a1 -> a1 -> a1) -> t -> a2) (Use FlexibleContexts to permit this) • When checking the inferred type it :: forall a1 t a2. (Integral a1, Num t, Num a2, Num ((a1 -> a1 -> a1) -> t -> a2), Eq a2) => [(a1 -> a1 -> a1) -> t -> a2] *Main> filter' (\x -> x `mod` 3 == 0) [3,4,5,7,8,12,13,14] filter' (\x -> x `mod` 3 == 0) [3,4,5,7,8,12,13,14] [3,12] *Main> map' (\x -> x `mod` 3 == 0) [3,4,5,7,8,12,13,14] map' (\x -> x `mod` 3 == 0) [3,4,5,7,8,12,13,14] [True,False,False,False,False,True,False,False] *Main> :t foldl :t foldl foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) curs4.hs:152:1: error: The type signature for ‘foldl'’ lacks an accompanying binding | 152 | foldl' :: (b -> a -> b) -> b -> [a] -> b | ^^^^^^ Failed, no modules loaded. Prelude> foldl :: (b -> a -> b) -> b -> [a] -> b foldl :: (b -> a -> b) -> b -> [a] -> b :107:1: error: • No instance for (Show ((b0 -> a0 -> b0) -> b0 -> [a0] -> b0)) 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 Prelude> :t foldl :: (b -> a -> b) -> b -> [a] -> b :t foldl :: (b -> a -> b) -> b -> [a] -> b foldl :: (b -> a -> b) -> b -> [a] -> b :: (b -> a -> b) -> b -> [a] -> b Prelude> foldl (+) 0 [1, 2, 3, 4] foldl (+) 0 [1, 2, 3, 4] 10 Prelude> foldl (*) 1 [1, 2, 3, 4] foldl (*) 1 [1, 2, 3, 4] 24 Prelude> foldl (*) 0 [1, 2, 3, 4] foldl (*) 0 [1, 2, 3, 4] 0 Prelude> :t foldr :t foldr foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b Prelude> foldl (*) 0 [1, 2, 3, 4] foldl (*) 0 [1, 2, 3, 4] 0 Prelude> foldr (*) 0 [1, 2, 3, 4] foldr (*) 0 [1, 2, 3, 4] 0 Prelude> foldr (*) 1 [1, 2, 3, 4] foldr (*) 1 [1, 2, 3, 4] 24 Prelude> foldr (+) 1 [1, 2, 3, 4] foldr (+) 1 [1, 2, 3, 4] 11 Prelude> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) curs4.hs:164:11: error: • Ambiguous type variable ‘t0’ arising from a use of ‘foldl’ prevents the constraint ‘(Foldable t0)’ from being solved. Relevant bindings include sumlist :: t0 Integer -> Integer (bound at curs4.hs:164:1) Probable fix: use a type annotation to specify what ‘t0’ should be. These potential instances exist: instance Foldable (Either a) -- Defined in ‘Data.Foldable’ instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Foldable ((,) a) -- Defined in ‘Data.Foldable’ ...plus one other ...plus 26 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the expression: foldl (+) 0 In an equation for ‘sumlist’: sumlist = foldl (+) 0 | 164 | sumlist = foldl (+) 0 | ^^^^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> sumlist [ 1, 2, 3, 4 ] sumlist [ 1, 2, 3, 4 ] 10 *Main> :t max :t max max :: Ord a => a -> a -> a *Main> max 2 3 max 2 3 3 *Main> max 7 3 max 7 3 7 *Main> :info Ord :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 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 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> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> maxlist [1, 3, 8, 5] maxlist [1, 3, 8, 5] 8 *Main> maxlist [1, 3, 8, 5, -10000] maxlist [1, 3, 8, 5, -10000] 8 *Main> maxlist [1, 3, 8, 5, 100000] maxlist [1, 3, 8, 5, 100000] 100000 *Main> maxlist [-10000, -100001] maxlist [-10000, -100001] -9999 *Main> maxlist [] maxlist [] -9999 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> maxlist 0 [ 1, 2, 3 2] maxlist 0 [ 1, 2, 3 2] :133:19: error: • No instance for (Num (Integer -> Int)) arising from the literal ‘3’ (maybe you haven't applied a function to enough arguments?) • In the expression: 3 In the expression: 3 2 In the second argument of ‘maxlist’, namely ‘[1, 2, 3 2]’ *Main> maxlist 0 [ 1, 2, 3, 2] maxlist 0 [ 1, 2, 3, 2] 3 *Main> :r :r [1 of 1] Compiling Main ( curs4.hs, interpreted ) Ok, one module loaded. *Main> maxlist' [1, 2, 3, 4] maxlist' [1, 2, 3, 4] 4 *Main> maxlist' [1, 2, 7, 3, 4] maxlist' [1, 2, 7, 3, 4] 7 *Main> maxlist' [] maxlist' [] *** Exception: Prelude.tail: empty list *Main> :info Maybe :info 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 ( curs4.hs, interpreted ) Ok, one module loaded. *Main> maxlist'' [1, 2, 3, 4, 2] maxlist'' [1, 2, 3, 4, 2] Just 4 *Main> maxlist'' [] maxlist'' [] Nothing *Main> sum sum :143:1: error: • No instance for (Show ([Integer] -> Integer)) 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> :t sum :t sum sum :: (Foldable t, Num a) => t a -> a *Main> sum [] sum [] 0 *Main> (\x | x `mod` 2 == 0 -> x + 4) 4 (\x | x `mod` 2 == 0 -> x + 4) 4 :146:5: error: parse error on input ‘|’ *Main>