GHCi

2006年4月9日
2 分

GHCiは対話的に操作できるインタプリタ。:help コマンドで使い方がわかる。

>ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.4.1, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base-1.0 ... linking ... done.
Prelude> :help
 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  ...           set options
   :set args <arg> ...         set the arguments returned by System.getArgs
   :set prog <progname>        set the value returned by System.getProgName
   :show modules               show the currently loaded modules
   :show bindings              show the current bindings made at the prompt
   :type <expr>                show the type of <expr>
   :kind <type>                show the kind of <type>
   :undef <cmd>                undefine user-defined command :<cmd>
   :unset  ...         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.)
Prelude> :quit
Leaving GHCi.
>

終了するには :quit。 関数の定義はできない。別途ファイルに保存して、:load コマンドで読み込む。

Prelude> :l addone.hs
Compiling Main             ( addone.hs, interpreted )
Ok, modules loaded: Main.
*Main> addOne 3
4