stefan@stefans-MacBook-Pro v2quicksort % cd cd stefan@stefans-MacBook-Pro ~ % cd teaching cd teaching stefan@stefans-MacBook-Pro teaching % cd pf-2022-2023/ cd pf-2022-2023/ stefan@stefans-MacBook-Pro pf-2022-2023 % cd c03 cd c03 cd: no such file or directory: c03 stefan@stefans-MacBook-Pro pf-2022-2023 % ls ls curs01 curs03 webpage curs02 old-2021-2022 stefan@stefans-MacBook-Pro pf-2022-2023 % cd curs03 cd curs03 stefan@stefans-MacBook-Pro curs03 % ls ls c03.hs stefan@stefans-MacBook-Pro curs03 % ghci ghci GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help :l c03 :l c03 Prelude> :l c03 [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> T T :3:1: error: • No instance for (Show Asdf) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :!clear :!clear *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> nextDay Thu nextDay Thu :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> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> nextDay Thu nextDay Thu Fri *Main> 4 / 5 4 / 5 0.8 *Main> 4 // 5 4 // 5 :11:3: error: • Variable not in scope: (//) :: t0 -> t1 -> t • Perhaps you meant one of these: ‘/=’ (imported from Prelude), ‘/’ (imported from Prelude) *Main> 4 `div` 5 4 `div` 5 0 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire 4 5 impartire 4 5 0 *Main> impartire 10 5 impartire 10 5 2 *Main> impartire 10 0 impartire 10 0 *** Exception: divide by zero *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire (-5) 5 impartire (-5) 5 -1 *Main> impartire (-5) 0 impartire (-5) 0 -1 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) c03.hs:38:1: error: Duplicate type signatures for ‘impartire’ at c03.hs:28:1-9 c03.hs:38:1-9 | 38 | impartire :: Int -> Int -> RezultatImpartire | ^^^^^^^^^ c03.hs:39:1: error: Multiple declarations of ‘impartire’ Declared at: c03.hs:29:1 c03.hs:39:1 | 39 | impartire x y = if y == 0 then | ^^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire (-5) 5 impartire (-5) 5 -1 *Main> impartire' (-5) 5 impartire' (-5) 5 :23:1: error: • No instance for (Show RezultatImpartire) arising from a use of ‘print’ • In a stmt of an interactive GHCi command: print it *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire' (-5) 5 impartire' (-5) 5 Valid *Main> impartire' 10 0 impartire' 10 0 Invalid *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire' 10 0 impartire' 10 0 (Invalid,-1) *Main> impartire' 10 2 impartire' 10 2 (Valid,5) *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire' 10 2 impartire' 10 2 Valid 5 *Main> impartire' 10 0 impartire' 10 0 Invalid *Main> (10, 20) (10, 20) (10,20) *Main> fst (10, 20) fst (10, 20) 10 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> Ctor 12 13 Ctor 12 13 Ctor 12 13 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> primul (Ctor 12 13) primul (Ctor 12 13) 12 *Main> (Cons 1 (Cons 2 (Cons 3 Nil))) (Cons 1 (Cons 2 (Cons 3 Nil))) :39:2: error: Data constructor not in scope: Cons :: t3 -> t0 -> t :39:10: error: Data constructor not in scope: Cons :: t4 -> t1 -> t0 :39:18: error: Data constructor not in scope: Cons :: t5 -> t2 -> t1 :39:25: error: Data constructor not in scope: Nil *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> (Cons 1 (Cons 2 (Cons 3 Nil))) (Cons 1 (Cons 2 (Cons 3 Nil))) Cons 1 (Cons 2 (Cons 3 Nil)) *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> countElems (Cons 1 (Cons 5 (Cons 7 Nil))) countElems (Cons 1 (Cons 5 (Cons 7 Nil))) 3 *Main> countElems (Cons 1 (Cons 5 (Cons 7 (Cons 9 Nil)))) countElems (Cons 1 (Cons 5 (Cons 7 (Cons 9 Nil)))) 4 *Main> countElems Nil countElems Nil 0 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> head (Cons 1 (Cons 2 Nil)) head (Cons 1 (Cons 2 Nil)) :48:1: error: Ambiguous occurrence ‘head’ It could refer to either ‘Prelude.head’, imported from ‘Prelude’ at c03.hs:1:1 (and originally defined in ‘GHC.List’) or ‘Main.head’, defined at c03.hs:76:1 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> head (Cons 1 (Cons 2 Nil)) head (Cons 1 (Cons 2 Nil)) :50:7: error: • Couldn't match expected type ‘[a]’ with actual type ‘Lista’ • In the first argument of ‘head’, namely ‘(Cons 1 (Cons 2 Nil))’ In the expression: head (Cons 1 (Cons 2 Nil)) In an equation for ‘it’: it = head (Cons 1 (Cons 2 Nil)) • Relevant bindings include it :: a (bound at :50:1) *Main> head' (Cons 1 (Cons 2 Nil)) head' (Cons 1 (Cons 2 Nil)) 1 *Main> head' Nil head' Nil *** Exception: c03.hs:76:1-21: Non-exhaustive patterns in function head' *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> head' Nil head' Nil NotOkay *Main> head' (Cons 1 (Cons 2 Nil)) head' (Cons 1 (Cons 2 Nil)) Okay *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> head' (Cons 1 (Cons 2 Nil)) head' (Cons 1 (Cons 2 Nil)) Okay 1 *Main> head' Nil head' Nil NotOkay *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> head'' (Cons 1 (Cons 7 Nil)) head'' (Cons 1 (Cons 7 Nil)) Bun 1 *Main> head'' Nil head'' Nil Rau *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire'' 10 0 impartire'' 10 0 Rau *Main> impartire'' 10 2 impartire'' 10 2 Bun 5 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> tail'' (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil))) tail'' (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil))) :66:46: error: parse error (possibly incorrect indentation or mismatched brackets) *Main> tail'' (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) tail'' (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) Bun (Cons 2 (Cons 3 (Cons 4 Nil))) *Main> tail'' Nil tail'' Nil Rau *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> count (Plic 1 (Plic 2 (Plic 3 Null))) count (Plic 1 (Plic 2 (Plic 3 Null))) 3 *Main> count (Plic False (Plic False (Plic True Null))) count (Plic False (Plic False (Plic True Null))) 3 *Main> count (Plic False (Plic False Null)) count (Plic False (Plic False Null)) 2 *Main> count (Plic 'A' (Plic 'B' Null)) count (Plic 'A' (Plic 'B' Null)) 2 *Main> count (Plic "Asdf" (Plic "Qerty" Null)) count (Plic "Asdf" (Plic "Qerty" Null)) 2 *Main> count (Plic (Plic 1 (Plic 2 Null)) (Plic Null Null)) count (Plic (Plic 1 (Plic 2 Null)) (Plic Null Null)) 2 *Main> count (Plic 'A' (Plic 'B' Null)) count (Plic 'A' (Plic 'B' Null)) 2 *Main> count (Plic 'A' (Plic 123 Null)) count (Plic 'A' (Plic 123 Null)) :77:23: error: • No instance for (Num Char) arising from the literal ‘123’ • In the first argument of ‘Plic’, namely ‘123’ In the second argument of ‘Plic’, namely ‘(Plic 123 Null)’ In the first argument of ‘count’, namely ‘(Plic 'A' (Plic 123 Null))’ *Main> :t (Plic 'A' (Plic 'b' Null)) :t (Plic 'A' (Plic 'b' Null)) (Plic 'A' (Plic 'b' Null)) :: List Char *Main> :t (Plic False (Plic True Null)) :t (Plic False (Plic True Null)) (Plic False (Plic True Null)) :: List Bool *Main> :t (Plic (Plic 'A' (Plic 'B' Null)) (Plic Null Null)) :t (Plic (Plic 'A' (Plic 'B' Null)) (Plic Null Null)) (Plic (Plic 'A' (Plic 'B' Null)) (Plic Null Null)) :: List (List Char) *Main> :t (Plic (Plic 'A' (Plic 'B' Null)) (Plic (Plic 'A' Null) Null)) :t (Plic (Plic 'A' (Plic 'B' Null)) (Plic (Plic 'A' Null) Null)) (Plic (Plic 'A' (Plic 'B' Null)) (Plic (Plic 'A' Null) Null)) :: List (List Char) *Main> :t Null :t Null Null :: List a *Main> :t Plic :t Plic Plic :: a -> List a -> List a *Main> :t Bun :t Bun Bun :: a -> Rezultat a *Main> :t Rau :t Rau Rau :: Rezultat a *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 ( c03.hs, interpreted ) c03.hs:121:23: error: • Couldn't match expected type ‘Maybe Integer’ with actual type ‘Integer’ • In the expression: (x `div` y) In the expression: if y == 0 then Nothing else (x `div` y) In an equation for ‘impartire'''’: impartire''' x y = if y == 0 then Nothing else (x `div` y) | 121 | (x `div` y) | ^^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartire''' 10 2 impartire''' 10 2 Just 5 *Main> impartire''' 10 0 impartire''' 10 0 Nothing *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> (Plic True (Plic False (Plic True Null)) (Plic True (Plic False (Plic True Null)) :92:41: error: parse error (possibly incorrect indentation or mismatched brackets) *Main> (Plic True (Plic False (Plic True Null))) (Plic True (Plic False (Plic True Null))) Plic True (Plic False (Plic True Null)) *Main> :t (Plic True (Plic False (Plic True Null))) :t (Plic True (Plic False (Plic True Null))) (Plic True (Plic False (Plic True Null))) :: List Bool *Main> :t (True : (False : (True : []))) :t (True : (False : (True : []))) (True : (False : (True : []))) :: [Bool] *Main> :t True : False : True : [] :t True : False : True : [] True : False : True : [] :: [Bool] *Main> :t [] :t [] [] :: [a] *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> count' True : False : True : [] count' True : False : True : [] :99:8: error: • Couldn't match expected type ‘[a0]’ with actual type ‘Bool’ • In the first argument of ‘count'’, namely ‘True’ In the first argument of ‘(:)’, namely ‘count' True’ In the expression: count' True : False : True : [] :99:15: error: • Couldn't match type ‘Bool’ with ‘Int’ Expected type: [Int] Actual type: [Bool] • In the second argument of ‘(:)’, namely ‘False : True : []’ In the expression: count' True : False : True : [] In an equation for ‘it’: it = count' True : False : True : [] *Main> :r :r Ok, one module loaded. *Main> count' True : False : True : [] count' True : False : True : [] :101:8: error: • Couldn't match expected type ‘[a0]’ with actual type ‘Bool’ • In the first argument of ‘count'’, namely ‘True’ In the first argument of ‘(:)’, namely ‘count' True’ In the expression: count' True : False : True : [] :101:15: error: • Couldn't match type ‘Bool’ with ‘Int’ Expected type: [Int] Actual type: [Bool] • In the second argument of ‘(:)’, namely ‘False : True : []’ In the expression: count' True : False : True : [] In an equation for ‘it’: it = count' True : False : True : [] *Main> :t count' :t count' count' :: [a] -> Int *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> :t count' :t count' count' :: [a] -> Int *Main> count' True : False : True : [] count' True : False : True : [] :105:8: error: • Couldn't match expected type ‘[a0]’ with actual type ‘Bool’ • In the first argument of ‘count'’, namely ‘True’ In the first argument of ‘(:)’, namely ‘count' True’ In the expression: count' True : False : True : [] :105:15: error: • Couldn't match type ‘Bool’ with ‘Int’ Expected type: [Int] Actual type: [Bool] • In the second argument of ‘(:)’, namely ‘False : True : []’ In the expression: count' True : False : True : [] In an equation for ‘it’: it = count' True : False : True : [] *Main> count' (True : False : True : []) count' (True : False : True : []) 3 *Main> count' (True : False : []) count' (True : False : []) 2 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> count' [ 1, 6, 5] count' [ 1, 6, 5] 3 *Main> count' [ 1, 6] count' [ 1, 6] 2 *Main> count' [] count' [] 0 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) c03.hs:132:1: error: Duplicate type signatures for ‘head''’ at c03.hs:89:1-6 c03.hs:132:1-6 | 132 | head'' :: Lista -> RezultatLista | ^^^^^^ c03.hs:133:1: error: Multiple declarations of ‘head''’ Declared at: c03.hs:90:1 c03.hs:133:1 | 133 | head'' (Cons x xs) = Okay x | ^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartireInLant 100 2 5 impartireInLant 100 2 5 Just 10 *Main> impartireInLant 100 5 5 impartireInLant 100 5 5 Just 4 *Main> impartireInLant 100 0 5 impartireInLant 100 0 5 Nothing *Main> impartireInLant 100 5 0 impartireInLant 100 5 0 Nothing *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 ( c03.hs, interpreted ) c03.hs:145:51: error: • Couldn't match expected type ‘Either Integer Int’ with actual type ‘Integer’ • In the expression: r' In a case alternative: Just r' -> r' In the expression: case impartire''' r z of Nothing -> Left 1 Just r' -> r' | 145 | Just r' -> r' | ^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) c03.hs:145:51: error: • Couldn't match type ‘Integer’ with ‘Int’ Expected type: Either Integer Int Actual type: Either Integer Integer • In the expression: Right r' In a case alternative: Just r' -> Right r' In the expression: case impartire''' r z of Nothing -> Left 1 Just r' -> Right r' | 145 | Just r' -> Right r' | ^^^^^^^^ Failed, no modules loaded. Prelude> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartireInLant' 100 2 5 impartireInLant' 100 2 5 Right 10 *Main> impartireInLant' 100 0 5 impartireInLant' 100 0 5 Left 0 *Main> impartireInLant' 100 5 0 impartireInLant' 100 5 0 Left 1 *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> impartireInLant' 100 5 0 impartireInLant' 100 5 0 Left Adoua *Main> impartireInLant' 100 0 5 impartireInLant' 100 0 5 Left Prima *Main> :r :r [1 of 1] Compiling Main ( c03.hs, interpreted ) Ok, one module loaded. *Main> eval (Add (Const 7) (Mul (Const 7) (Add (Const 4) (Const 2)))) eval (Add (Const 7) (Mul (Const 7) (Add (Const 4) (Const 2)))) 49 *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 Bounded Bool -- Defined in ‘GHC.Enum’ instance Read Bool -- Defined in ‘GHC.Read’ *Main>