$ ghci lec-2-13.hs GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :q Leaving GHCi. $ ghci lec-2-13.hs GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:20:19: error: Not in scope: type constructor or class ‘Empty’ | 20 | g :: Either (a -> Empty) b -> (a -> b) | ^^^^^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :q Leaving GHCi. $ ghci lec-2-13.hs GHCi, version 8.8.4: https://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> f 1 1 *Main> f "hello" "hello" *Main> :t f f f f :: a -> a *Main> f f :4:1: error: • No instance for (Show (a0 -> a0)) 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 True True :: Bool *Main> :t False False :: Bool *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> T T *Main> :t T T :: MyBoolean *Main> :t and and :: Foldable t => t Bool -> Bool *Main> :t (&&) (&&) :: Bool -> Bool -> Bool *Main> False && True False *Main> :info (&&) (&&) :: Bool -> Bool -> Bool -- Defined in ‘GHC.Classes’ infixr 3 && *Main> False || True True *Main> :info (||) (||) :: Bool -> Bool -> Bool -- Defined in ‘GHC.Classes’ infixr 2 || *Main> :t () () :: () *Main> :t Left Left :: a -> Either a b *Main> :t Right Right :: b -> Either a b *Main> :t Left () Left () :: Either () b *Main> :t Right () Right () :: Either a () *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:11:10: error: parse error on input ‘(’ | 11 | deriving (Show) | ^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :t Left' Left' :: a -> MyEither a b *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:26:5: error: • Couldn't match type ‘Either (a -> Empty) b’ with ‘a -> b’ Expected type: Either (a -> Empty) b -> a -> b Actual type: (a -> b) -> a -> b • In the expression: f In an equation for ‘g’: g = f • Relevant bindings include g :: Either (a -> Empty) b -> a -> b (bound at lec-2-13.hs:26:1) | 26 | g = f | ^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:28:15: error: Variable not in scope: abort :: Empty -> b | 28 | Left z -> abort (z y) | ^^^^^ Failed, no modules loaded. Prelude> :t error error :: [Char] -> a Prelude> error "help!" *** Exception: help! CallStack (from HasCallStack): error, called at :28:1 in interactive:Ghci1 Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:30:22: error: • Occurs check: cannot construct the infinite type: a ~ (a -> Empty) -> Empty • The function ‘y’ is applied to one argument, but its type ‘a’ has none In the first argument of ‘abort’, namely ‘(y z)’ In the expression: abort (y z) • Relevant bindings include z :: a -> Empty (bound at lec-2-13.hs:30:10) y :: a (bound at lec-2-13.hs:28:5) x :: Either (a -> Empty) b (bound at lec-2-13.hs:28:3) g :: Either (a -> Empty) b -> a -> b (bound at lec-2-13.hs:28:1) | 30 | Left z -> abort (y z) | ^^^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) lec-2-13.hs:30:22: error: • Occurs check: cannot construct the infinite type: a ~ (a -> Empty) -> Empty • The function ‘y’ is applied to one argument, but its type ‘a’ has none In the first argument of ‘abort’, namely ‘(y z)’ In the expression: abort (y z) • Relevant bindings include z :: a -> Empty (bound at lec-2-13.hs:30:10) y :: a (bound at lec-2-13.hs:28:5) x :: Either (a -> Empty) b (bound at lec-2-13.hs:28:3) g :: Either (a -> Empty) b -> a -> b (bound at lec-2-13.hs:28:1) | 30 | Left z -> abort (y z) | ^^^ Failed, no modules loaded. Prelude> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :t (==) (==) :: Eq a => a -> a -> Bool *Main> :t show show :: Show a => a -> String *Main> show True "True" *Main> show 1 "1" *Main> show (1+1) "2" *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> safeDiv 10 10 Right 1 *Main> safeDiv 10 0 Left "div by zero" *Main> :t (1, 2) (1, 2) :: (Num a, Num b) => (a, b) *Main> :t fst fst :: (a, b) -> a *Main> :t snd snd :: (a, b) -> b *Main> fst (1,2) 1 *Main> :t [1,2,3,4] [1,2,3,4] :: Num a => [a] *Main> :t ['a', 'b', 'c'] ['a', 'b', 'c'] :: [Char] *Main> :t [1, "a"] :1:2: error: • No instance for (Num [Char]) arising from the literal ‘1’ • In the expression: 1 In the expression: [1, "a"] *Main> :t map map :: (a -> b) -> [a] -> [b] *Main> map (\ x -> x + 1) [1 .. 10] [2,3,4,5,6,7,8,9,10,11] *Main> map (\ x -> x + 1) ['a', 'b'] :51:13: error: • No instance for (Num Char) arising from a use of ‘+’ • In the expression: x + 1 In the first argument of ‘map’, namely ‘(\ x -> x + 1)’ In the expression: map (\ x -> x + 1) ['a', 'b'] *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> add3 10 12 == add1 10 12 True *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> fac 10 3628800 *Main> fac 100 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> fac' 10 3628800 *Main> fac' 100 0 *Main> :t putStrLn putStrLn :: String -> IO () *Main> putStrLn "hello world!" hello world! *Main> :t getLine getLine :: IO String *Main> :t ($) ($) :: (a -> b) -> a -> b *Main> :info ($) ($) :: (a -> b) -> a -> b -- Defined in ‘GHC.Base’ infixr 0 $ *Main> :t (++) (++) :: [a] -> [a] -> [a] *Main> :info (++) (++) :: [a] -> [a] -> [a] -- Defined in ‘GHC.Base’ infixr 5 ++ *Main> hello welcome to haskell, what is your name? Frank welcome Frank! *Main> :t return return :: Monad m => a -> m a *Main> :r [1 of 1] Compiling Main ( lec-2-13.hs, interpreted ) Ok, one module loaded. *Main> hello' welcome to haskell, what is your name? frank welcome frank! welcome to haskell, what is your name? C-c C-cInterrupted. *Main> :q Leaving GHCi. $ ls 2024-02-13-Note-12-21.xopp lec-1-30.pdf circuit1.pdf lec-1-9.pdf circuit2.pdf lec-2-13.hs circuit3.pdf lec-2-13.hs~ haskell101.hs lec-2-1.pdf haskell101.hs~ lec-2-6.pdf lec-1-11.pdf lec-2-8.pdf lec-1-16.pdf Prog1.pdf lec-1-18.pdf Prog2.pdf lec-1-23.pdf Quipper101.hs lec-1-25.pdf $ ghc lec-2-13.hs [1 of 1] Compiling Main ( lec-2-13.hs, lec-2-13.o ) Linking lec-2-13 ... $ ./lec-2-13 welcome to haskell, what is your name? what welcome what! welcome to haskell, what is your name? whatis welcome whatis ! welcome to haskell, what is your name? C-c C-c