X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fghci.xml;h=9ec07c355e0ab68f1bae0f660e33a9f5ab23ee73;hb=143f4381d242e4a1c3174e8a0732a1e48f00a1aa;hp=de06cb407a77e55d31a84b673b40abed8214e9e9;hpb=2fed3e94049de8f31da7e0586e719d7f29398428;p=ghc-hetmet.git diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index de06cb4..9ec07c3 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -28,12 +28,11 @@ $ ghci ___ ___ _ / _ \ /\ /\/ __(_) - / /_\// /_/ / / | | GHC Interactive, version 5.04, for Haskell 98. + / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. -Loading package haskell98 ... linking ... done. Prelude> @@ -45,40 +44,41 @@ Prelude> Commands available from the prompt: - <stmt> evaluate/run <stmt> - :add <filename> ... add module(s) to the current target set - :browse [*]<module> display the names defined by <module> - :cd <dir> change directory to <dir> - :def <cmd> <expr> define a command :<cmd> - :help, :? display this list of commands - :info [<name> ...] display information about the given names - :load <filename> ... load module(s) and their dependents - :module [+/-] [*]<mod> ... set the context for expression evaluation - :reload reload the current module set - - :set <option> ... set options - :set args <arg> ... set the arguments returned by System.getArgs - :set prog <progname> set the value returned by System.getProgName - :set prompt <prompt> set the prompt used in GHCi - - :show modules show the currently loaded modules - :show bindings show the current bindings made at the prompt - - :ctags [<file>] create tags file for Vi (default: "tags") - :etags [<file>] create tags file for Emacs (default: "TAGS") - :type <expr> show the type of <expr> - :kind <type> show the kind of <type> - :undef <cmd> undefine user-defined command :<cmd> - :unset <option> ... unset options - :quit exit GHCi - :!<command> run the shell command <command> - - Options for `:set' and `:unset': - - +r revert top-level expressions after each evaluation - +s print timing/memory stats after each evaluation - +t print type after evaluation - -<flags> most GHC command line flags can also be set here + <stmt> evaluate/run <stmt> + :add <filename> ... add module(s) to the current target set + :browse [*]<module> display the names defined by <module> + :cd <dir> change directory to <dir> + :def <cmd> <expr> define a command :<cmd> + :help, :? display this list of commands + :info [<name> ...] display information about the given names + :load <filename> ... load module(s) and their dependents + :module [+/-] [*]<mod> ... set the context for expression evaluation + :main [<arguments> ...] run the main function with the given arguments + :reload reload the current module set + + :set <option> ... set options + :set args <arg> ... set the arguments returned by System.getArgs + :set prog <progname> set the value returned by System.getProgName + :set prompt <prompt> set the prompt used in GHCi + + :show modules show the currently loaded modules + :show bindings show the current bindings made at the prompt + + :ctags [<file>] create tags file for Vi (default: "tags") + :etags [<file>] create tags file for Emacs (defauilt: "TAGS") + :type <expr> show the type of <expr> + :kind <type> show the kind of <type> + :undef <cmd> undefine user-defined command :<cmd> + :unset <option> ... unset options + :quit exit GHCi + :!<command> run the shell command <command> + + Options for ':set' and ':unset': + + +r revert top-level expressions after each evaluation + +s print timing/memory stats after each evaluation + +t print type after evaluation + -<flags> most GHC command line flags can also be set here (eg. -v2, -fglasgow-exts, etc.) @@ -350,7 +350,7 @@ Ok, modules loaded: A, B, C, D. HINT: since GHCi will only use a compiled object file if it - can sure that the compiled version is up-to-date, a good technique + can be sure that the compiled version is up-to-date, a good technique when working on a large program is to occasionally run ghc ––make to compile the whole project (say before you go for lunch :-), then continue working in the @@ -561,9 +561,9 @@ Compiling Main ( Main.hs, interpreted ) Prelude> :module +IO -Prelude,IO> hPutStrLn stdout "hello\n" +Prelude IO> hPutStrLn stdout "hello\n" hello -Prelude,IO> +Prelude IO> (Note: :module can be shortened to @@ -593,7 +593,7 @@ Prelude,IO> Bar, then the scope will be set to *Bar if Bar is interpreted, or if Bar is compiled it will be - set to Prelude,Bar (GHCi automatically adds + set to Prelude Bar (GHCi automatically adds Prelude if it isn't present and there aren't any *-form modules). @@ -604,6 +604,12 @@ Prelude,IO> behaves in the same way for expressions typed at the prompt. + + Hint: GHCi will tab-complete names that are in scope; for + example, if you run GHCi and type J<tab> + then GHCi will expand it to Just . + + Qualified names @@ -612,6 +618,34 @@ Prelude,IO> qualified declaration for every module in every package, and every module currently loaded into GHCi. + + + The <literal>:main</literal> command + + + When a program is compiled and executed, it can use the + getArgs function to access the + command-line arguments. + However, we cannot simply pass the arguments to the + main function while we are testing in ghci, + as the main function doesn't take its + directly. + + + + Instead, we can use the :main command. + This runs whatever main is in scope, with + any arguments being treated the same as command-line arguments, + e.g.: + + + +Prelude> let main = System.Environment.getArgs >>= print +Prelude> :main foo bar +["foo","bar"] + + + @@ -633,9 +667,9 @@ Prelude> it * 2 expression, and if it doesn't have an IO type, then it transforms it as follows: an expression e turns into - - let it = e; - print it + +let it = e; +print it which is then run as an IO-action. @@ -644,10 +678,14 @@ Prelude> it * 2 complain: -Prelude> id -No instance for `Show (a -> a)' -arising from use of `print' -in a `do' expression pattern binding: print it +Prelude> id + +<interactive>:1:0: + No instance for (Show (a -> a)) + arising from use of `print' at <interactive>:1:0-1 + Possible fix: add an instance declaration for (Show (a -> a)) + In the expression: print it + In a 'do' expression: print it The error message contains some clues as to the @@ -659,14 +697,15 @@ in a `do' expression pattern binding: print it which is of type a. eg.: Prelude> Time.getClockTime +Wed Mar 14 12:23:13 GMT 2001 Prelude> print it Wed Mar 14 12:23:13 GMT 2001 The corresponding translation for an IO-typed e is - - it <- e + +it <- e @@ -759,22 +798,15 @@ $ ghci Main.hs package be loaded by using the -package flag: -$ ghci -package data +$ ghci -package readline ___ ___ _ / _ \ /\ /\/ __(_) - / /_\// /_/ / / | | GHC Interactive, version 5.05, for Haskell 98. + / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. -Loading package haskell98 ... linking ... done. -Loading package lang ... linking ... done. -Loading package concurrent ... linking ... done. -Loading package readline ... linking ... done. -Loading package unix ... linking ... done. -Loading package posix ... linking ... done. -Loading package util ... linking ... done. -Loading package data ... linking ... done. +Loading package readline-1.0 ... linking ... done. Prelude> @@ -847,10 +879,8 @@ $ ghci -lm GHCi commands all begin with ‘:’ and consist of a single command name followed by zero or more parameters. The command name may be - abbreviated, as long as the abbreviation is not ambiguous. All of - the builtin commands, with the exception of - :unset and :undef, may be - abbreviated to a single letter. + abbreviated, with ambiguities being resolved in favour of the more + commonly used commands. @@ -1048,6 +1078,38 @@ Prelude> :. cmds.ghci + :main arg1 ... argn + :main + + + + When a program is compiled and executed, it can use the + getArgs function to access the + command-line arguments. + However, we cannot simply pass the arguments to the + main function while we are testing in ghci, + as the main function doesn't take its + directly. + + + + Instead, we can use the :main command. + This runs whatever main is in scope, with + any arguments being treated the same as command-line arguments, + e.g.: + + + +Prelude> let main = System.Environment.getArgs >>= print +Prelude> :main foo bar +["foo","bar"] + + + + + + + :module +|- *mod1 ... *modn :module