Tutorial by Examples

Type ghci at a shell prompt to start GHCI. $ ghci GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Prelude>
By default, GHCI's prompt shows all the modules you have loaded into your interactive session. If you have many modules loaded this can get long: Prelude Data.List Control.Monad> -- etc The :set prompt command changes the prompt for this interactive session. Prelude Data.List Control.Monad&g...
GHCi uses a configuration file in ~/.ghci. A configuration file consists of a sequence of commands which GHCi will execute on startup. $ echo ":set prompt \"foo> \"" > ~/.ghci $ ghci GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration...
The :l or :load command type-checks and loads a file. $ echo "f = putStrLn \"example\"" > example.hs $ ghci GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help ghci> :l example.hs [1 of 1] Compiling Main ( example.hs, interpreted ) Ok, modules ...
You can quit GHCi simply with :q or :quit ghci> :q Leaving GHCi. ghci> :quit Leaving GHCi. Alternatively, the shortcut CTRL+D (Cmd+D for OSX) has the same effect as :q.
If you have loaded a file into GHCi (e.g. using :l filename.hs) and you have changed the file in an editor outside of GHCi you must reload the file with :r or :reload in order to make use of the changes, hence you don't need to type again the filename. ghci> :r OK, modules loaded: Main. ghci...
GHCi supports imperative-style breakpoints out of the box with interpreted code (code that's been :loaded). With the following program: -- mySum.hs doSum n = do putStrLn ("Counting to " ++ (show n)) let v = sum [1..n] putStrLn ("sum to " ++ (show n) ++ " = "...
The :{ instruction begins multi-line mode and :} ends it. In multi-line mode GHCi will interpret newlines as semicolons, not as the end of an instruction. ghci> :{ ghci| myFoldr f z [] = z ghci| myFoldr f z (y:ys) = f y (myFoldr f z ys) ghci| :} ghci> :t myFoldr myFoldr :: (a -> b -&g...

Page 1 of 1