stefan@stefans-MBP week10 % ghci ghci Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help macro 'doc' overwrites builtin command. Use ':def!' to overwrite. Loaded GHCi configuration from /Users/stefan/.ghci ghci> :l main :l main [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> f () f () () ghci> :q :q Leaving GHCi. stefan@stefans-MBP week10 % ghc -o main main.hs ghc -o main main.hs Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default [1 of 2] Compiling Main ( main.hs, main.o ) [2 of 2] Linking main stefan@stefans-MBP week10 % ls -al ls -al total 2792 drwxr-xr-x 7 stefan staff 224 May 5 14:13 . drwxr-xr-x 22 stefan staff 704 May 5 12:26 .. drwxr-xr-x 15 stefan staff 480 May 5 13:40 exproj -rwxr-xr-x@ 1 stefan staff 1415120 May 5 14:13 main -rw-r--r--@ 1 stefan staff 717 May 5 14:13 main.hi -rw-r--r--@ 1 stefan staff 391 May 5 14:12 main.hs -rw-r--r--@ 1 stefan staff 2464 May 5 14:13 main.o stefan@stefans-MBP week10 % ./main ./main Hello, World! stefan@stefans-MBP week10 % ghci ghci Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help macro 'doc' overwrites builtin command. Use ':def!' to overwrite. Loaded GHCi configuration from /Users/stefan/.ghci ghci> main main :1:1: error: Variable not in scope: main Suggested fix: Perhaps use ‘min’ (imported from Prelude) ghci> :l main :l main [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> main main Hello, World! ghci> :t putStrLn :t putStrLn putStrLn :: String -> IO () ghci> :t (>>) :t (>>) (>>) :: Monad m => m a -> m b -> m b ghci> :i IO :i IO type IO :: * -> * newtype IO a = ghc-prim-0.9.1:GHC.Types.IO (ghc-prim-0.9.1:GHC.Prim.State# ghc-prim-0.9.1:GHC.Prim.RealWorld -> (# ghc-prim-0.9.1:GHC.Prim.State# ghc-prim-0.9.1:GHC.Prim.RealWorld, a #)) -- Defined in ‘ghc-prim-0.9.1:GHC.Types’ instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’ instance Semigroup a => Semigroup (IO a) -- Defined in ‘GHC.Base’ instance Applicative IO -- Defined in ‘GHC.Base’ instance Functor IO -- Defined in ‘GHC.Base’ instance MonadFail IO -- Defined in ‘Control.Monad.Fail’ instance Monad IO -- Defined in ‘GHC.Base’ ghci> :t (>>) :t (>>) (>>) :: Monad m => m a -> m b -> m b ghci> main main Hello, World! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! Hello, X! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! Hello, X! Bye! ghci> :t getLine :t getLine getLine :: IO String ghci> :i putStr :i putStr putStr :: String -> IO () -- Defined in ‘System.IO’ ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! What is your name? S S Bye! ghci> :t (>>) :t (>>) (>>) :: Monad m => m a -> m b -> m b ghci> :t (>>=) :t (>>=) (>>=) :: Monad m => m a -> (a -> m b) -> m b ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! What is your name? S S Bye, S! ghci> :i Monad :i Monad type Monad :: (* -> *) -> Constraint class Applicative m => Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a {-# MINIMAL (>>=) #-} -- Defined in ‘GHC.Base’ instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’ instance (Monoid a, Monoid b) => Monad ((,,) a b) -- Defined in ‘GHC.Base’ instance (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) -- Defined in ‘GHC.Base’ instance Monad ((->) r) -- Defined in ‘GHC.Base’ instance Monad IO -- Defined in ‘GHC.Base’ instance Monad Maybe -- Defined in ‘GHC.Base’ instance Monad Solo -- Defined in ‘GHC.Base’ instance Monad [] -- Defined in ‘GHC.Base’ instance Monad (Either e) -- Defined in ‘Data.Either’ ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! What is your name? Stefan Stefan Bye, Stefan! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main main Hello, World! What is your name? Stef Stef V6: Bye, Stef! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] main.hs:41:9: error: Unexpected do block in function application: do putStrLn "Hello, World!" putStr "What is your name? " Suggested fixes: • Use parentheses. • Perhaps you intended to use BlockArguments | 41 | main6 = do putStrLn "Hello, World!" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^... main.hs:43:16: error: parse error on input ‘<-’ Suggested fix: Possibly caused by a missing 'do'? | 43 | name <- getLine | ^^ Failed, no modules loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] main.hs:47:1: error: Multiple declarations of ‘main6’ Declared at: main.hs:41:1 main.hs:47:1 | 47 | main6 = do putStrLn "Hello, World!" | ^^^^^ Failed, no modules loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> :r :r Ok, one module loaded. ghci> main7 main7 Hello, World! What is your name? X X V6: Bye, X! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> X X :33:1: error: Data constructor not in scope: X ghci> main7 main7 Hello, World! What is your name? X X V7: Bye, X! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main8 main8 Hello, World! What is your name? ASDF ASDF V8: Bye, ASDF! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] main.hs:66:10: error: Unexpected do block in function application: do putStrLn "Hello, World!" Suggested fixes: • Use parentheses. • Perhaps you intended to use BlockArguments | 66 | main10 = do putStrLn "Hello, World!" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ main.hs:68:12: error: Unexpected let expression in function application: let name = getLine in putStrLn $ "V9: Bye, " ++ name ++ "!" Suggested fixes: • Use parentheses. • Perhaps you intended to use BlockArguments | 68 | let name = getLine in | ^^^^^^^^^^^^^^^^^^^^^^... Failed, no modules loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) main.hs:69:41: error: • Couldn't match expected type: [Char] with actual type: IO String • In the first argument of ‘(++)’, namely ‘name’ In the second argument of ‘(++)’, namely ‘name ++ "!"’ In the second argument of ‘($)’, namely ‘"V9: Bye, " ++ name ++ "!"’ | 69 | putStrLn $ "V9: Bye, " ++ name ++ "!" | ^^^^ Failed, no modules loaded. ghci> :t getLine :t getLine getLine :: IO String ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> main10 main10 Hello, World! What is your name? ASASASASASASAS ASASASASASASAS V9: Bye, ASASASASASASAS! ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main11 main11 What is your name? Stefan Stefan Hello, Stefan! What is your name? Asdf Asdf Hello, Asdf! What is your name? X X Hello, X! What is your name? ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> main12 main12 What is your name? Stefan Stefan Hello, Stefan! ghci> :t return :t return return :: Monad m => a -> m a ghci> :t getArgs :t getArgs :1:1: error: Variable not in scope: getArgs ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] main.hs:100:11: error: The last statement in a 'do' block must be an expression args <- getArgs | 100 | main = do args <- getArgs | ^^^^^^^^^^^^^^^ Failed, no modules loaded. ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> :t getArgs :t getArgs :1:1: error: Variable not in scope: getArgs ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> :t getArgs :t getArgs getArgs :: IO [String] ghci> :r :r [1 of 2] Compiling Main ( main.hs, interpreted ) [Source file changed] Ok, one module loaded. ghci> :q :q Leaving GHCi. stefan@stefans-MBP week10 % ghc -o main main.hs ghc -o main main.hs Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default [1 of 2] Compiling Main ( main.hs, main.o ) [Source file changed] [2 of 2] Linking main [Objects changed] stefan@stefans-MBP week10 % ./main 10 20 asdf ./main 10 20 asdf ["10","20","asdf"] stefan@stefans-MBP week10 % ghci ghci Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help macro 'doc' overwrites builtin command. Use ':def!' to overwrite. Loaded GHCi configuration from /Users/stefan/.ghci ghci> import System.IO import System.IO ghci> :t getProgName :t getProgName :1:1: error: Variable not in scope: getProgName ghci> import System.Environment import System.Environment ghci> :t getProgName :t getProgName getProgName :: IO String ghci> :r :r Ok, no modules loaded. ghci> :q :q Leaving GHCi. stefan@stefans-MBP week10 % ghc -o main main.hs ghc -o main main.hs Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default [1 of 2] Compiling Main ( main.hs, main.o ) [Source file changed] [2 of 2] Linking main [Objects changed] stefan@stefans-MBP week10 % ./main 10 20 asdf ./main 10 20 asdf ["10","20","asdf"] Fisierul este: main stefan@stefans-MBP week10 % cd .. cd .. stefan@stefans-MBP pf-2024-2025 % ./week10/main 10 20 asdf ./week10/main 10 20 asdf ["10","20","asdf"] Fisierul este: main stefan@stefans-MBP pf-2024-2025 % cd week10 cd week10 stefan@stefans-MBP week10 % ls ls exproj main main.hi main.hs main.o stefan@stefans-MBP week10 % ghci ghci Loaded package environment from /Users/stefan/.ghc/x86_64-darwin-9.4.8/environments/default GHCi, version 9.4.8: https://www.haskell.org/ghc/ :? for help macro 'doc' overwrites builtin command. Use ':def!' to overwrite. Loaded GHCi configuration from /Users/stefan/.ghci ghci> :l main :l main [1 of 2] Compiling Main ( main.hs, interpreted ) Ok, one module loaded. ghci> main main [] Fisierul este: ghci> :help :help Commands available from the prompt: evaluate/run : repeat last command :{\n ..lines.. \n:}\n multiline command :add [*] ... add module(s) to the current target set :browse[!] [[*]] display the names defined by module (!: more details; *: all top-level names) :cd change directory to :cmd run the commands returned by ::IO String :complete [] list completions for partial input string :ctags[!] [] create tags file for Vi (default: "tags") (!: use regex instead of line number) :def[!] define command : (later defined command has precedence, :: is always a builtin command) (!: redefine an existing command name) :doc display docs for the given name (experimental) :edit edit file :edit edit last module :etags [] create tags file for Emacs (default: "TAGS") :help, :? display this list of commands :info[!] [ ...] display information about the given names (!: do not filter instances) :instances display the class instances available for :issafe [] display safe haskell information of module :kind[!] show the kind of (!: also print the normalised type) :load[!] [*] ... load module(s) and their dependents (!: defer type errors) :main [ ...] run the main function with the given arguments :module [+/-] [*] ... set the context for expression evaluation :quit exit GHCi :reload[!] reload the current module set (!: defer type errors) :run function [ ...] run the function with the given arguments :script run the script :type show the type of :type +d show the type of , defaulting type variables :unadd ... remove module(s) from the current target set :undef undefine user-defined command : :: run the builtin command :! run the shell command -- Commands for debugging: :abandon at a breakpoint, abandon current computation :back [] go back in the history N steps (after :trace) :break [] [] set a breakpoint at the specified location :break set a breakpoint on the specified function :continue [] resume after a breakpoint [and set break ignore count] :delete ... delete the specified breakpoints :delete * delete all breakpoints :disable ... disable the specified breakpoints :disable * disable all breakpoints :enable ... enable the specified breakpoints :enable * enable all breakpoints :force print , forcing unevaluated parts :forward [] go forward in the history N step s(after :back) :history [] after :trace, show the execution history :ignore for break set break ignore :list show the source code around current breakpoint :list show the source code for :list [] show the source code around line number :print [ ...] show a value without forcing its computation :sprint [ ...] simplified version of :print :step single-step after stopping at a breakpoint :step single-step into :steplocal single-step within the current top-level binding :stepmodule single-step restricted to the current module :trace trace after stopping at a breakpoint :trace evaluate with tracing on (see :history) -- Commands for changing settings: :set