From 0793be14161a8240259786a1edad400bc8577a93 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 20 Mar 2001 15:37:52 +0000 Subject: [PATCH] [project @ 2001-03-20 15:37:52 by simonmar] - add index terms - elaborate the description of the 'it' variable --- ghc/docs/users_guide/ghci.sgml | 76 +++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/ghc/docs/users_guide/ghci.sgml b/ghc/docs/users_guide/ghci.sgml index 412b0a5..35694a5 100644 --- a/ghc/docs/users_guide/ghci.sgml +++ b/ghc/docs/users_guide/ghci.sgml @@ -1,7 +1,8 @@ Using GHCi GHCi - interpreter + interpreterGHCi + interactiveGHCi GHCi The ‘i’ stands for “Interactive” @@ -13,6 +14,8 @@ also has support for interactively loading compiled code, as well as supporting allexcept the FFI, at the moment the language extensions that GHC provides. + FFIGHCi support + Foreign Function InterfaceGHCi support Introduction to GHCi @@ -96,6 +99,7 @@ fac n = n * fac (n-1) To load a Haskell source file into GHCi, use the :load command: + :load Prelude> :load Main @@ -127,6 +131,8 @@ Main> fac 17 Modules vs. filenames + modulesand filenames + filenamesof modules Question: How does GHC find the filename which contains module M? Answer: it looks for the @@ -151,6 +157,7 @@ Main> fac 17 Making changes and recompilation + :reload If you make some changes to the source code and want GHCi to recompile the program, give the :reload @@ -164,6 +171,7 @@ Main> fac 17 Loading compiled code + compiled codein GHCi When you load a Haskell source module into GHCi, it is normally converted to byte-code and run using the interpreter. @@ -300,11 +308,14 @@ hello What actually happens is that GHCi typechecks the expression, and if it doesn't have an IO type, then it transforms it as follows: an expression - e turns into let it = - e in print it. It then runs - the new expression as an IO-action. + e turns into + + let it = e; + print it + + which is then run as an IO-action. - Hence the original expression must have a type which is an + Hence, the original expression must have a type which is an instance of the Show class, or GHCi will complain: @@ -329,8 +340,8 @@ in a `do' expression pattern binding: print it The context module is shown in the prompt: for example, the prompt Prelude> indicates that the current context for evaluating expressions is the Haskell - Prelude module. This is the default context - when you start up GHCi. + Prelude module. The Prelude is the default + context when you start up GHCi. Prelude Exactly which entities are in scope in a given context @@ -379,6 +390,8 @@ in a `do' expression pattern binding: print it Using <literal>do-</literal>notation at the prompt + do-notationin GHCi + statementsin GHCi GHCi actually accepts statements rather than just expressions at the prompt. This means you can @@ -443,6 +456,7 @@ Prelude> HINT: if you turn on the +t option, GHCi will show the type of each variable bound by a statement. For example: + +t Prelude> :set +t Prelude> let (x:xs) = [1..] @@ -467,6 +481,16 @@ Prelude> it * 2 6 + This is a result of the translation mentioned earlier, + namely that an expression e is + translated to + + let it = e; + print it + + before execution, resulting in a binding for + it. + If the expression was of type IO a for some a, then it will be bound to the result of the IO computation, @@ -477,6 +501,13 @@ Prelude> print it Wed Mar 14 12:23:13 GMT 2001 + The corresponding translation for an IO-typed + e is + + it <- e + + + Note that it is shadowed by the new value each time you evaluate a new expression, and the old value of it is lost. @@ -486,13 +517,15 @@ Wed Mar 14 12:23:13 GMT 2001 Invoking GHCi + invokingGHCi + GHCi is invoked with the command ghci or ghc --interactive. A module or filename can also be specified on the command line; this instructs GHCi to load the that module or filename (and all the modules it depends on), - just as if you had said - :load module at the GHCi prompt + just as if you had said :load + module at the GHCi prompt (see ). For example, to start GHCi and load the program whose topmost module is in the file Main.hs, we could say: @@ -512,6 +545,7 @@ $ ghci Main.hs Packages + packageswith GHCi GHCi can make use of all the packages that come with GHC, but note: packages must be specified on the @@ -542,6 +576,7 @@ Prelude> Extra libraries + librarieswith GHCi Extra libraries may be specified on the command line using the normal -llib @@ -581,6 +616,7 @@ $ ghci -lm :cd dir + :cd Changes the current working directory to dir. A @@ -593,6 +629,7 @@ $ ghci -lm :def + :def ToDo. @@ -600,7 +637,9 @@ $ ghci -lm :help + :help :? + :? Displays a list of the available commands. @@ -608,6 +647,7 @@ $ ghci -lm :load module + :load Recursively loads module (which may be a module name or filename), and all the @@ -619,6 +659,7 @@ $ ghci -lm :module module + :module Sets the current context for statements typed at the prompt to module, which must be a @@ -631,6 +672,7 @@ $ ghci -lm :quit module + :quit Quits GHCi. You can also quit by typing a control-D at the prompt. @@ -639,6 +681,7 @@ $ ghci -lm :reload + :reload Attempts to reload the current target (see :load) if it, or any module it depends @@ -650,6 +693,7 @@ $ ghci -lm :set option... + :set Sets various options. See for a list of available options. The @@ -660,6 +704,7 @@ $ ghci -lm :type expression + :type Infers and prints the type of expression, including explicit @@ -671,6 +716,7 @@ $ ghci -lm :unset option... + :unset Unsets certain options. See for a list of available options. @@ -679,6 +725,8 @@ $ ghci -lm :! command... + :! + shell commandsin GHCi Executes the shell command command. @@ -690,6 +738,7 @@ $ ghci -lm The <literal>:set</literal> command + :set The :set command sets two types of options: GHCi options, which begin with @@ -703,6 +752,9 @@ $ ghci -lm +r + +r + CAFsin GHCi + Constant Applicative FormCAFs Normally, any evaluation of top-level expressions (otherwise known as CAFs or Constant Applicative Forms) in @@ -720,6 +772,7 @@ $ ghci -lm +s + +s Display some stats after evaluating each expression, including the elapsed time and number of bytes allocated. @@ -732,6 +785,7 @@ $ ghci -lm +t + +t Display the type of each variable bound after a statement is entered at the prompt. If the statement is a @@ -748,6 +802,8 @@ $ ghci -lm (, , and in particular) will also work, but may not take effect until the next reload. + dynamicoptions + staticoptions @@ -788,6 +844,8 @@ $ ghci -lm System.exit causes GHCi to exit! + System.exitin + GHCi Yes, it does. -- 1.7.10.4