X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fghci.xml;h=e79fb46c3f3df2c7164201b2a0edb22aea3bd6d7;hb=72eb3683f8a5a50588df662f9ba77d1d01f05cef;hp=de56c7215132dc739daf901674e0b88bea630512;hpb=2aa838b02f1c84459e971dafcc08afa890b02cbf;p=ghc-hetmet.git diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index de56c72..e79fb46 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -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). @@ -612,6 +612,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 +661,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 +672,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 +691,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 +792,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>