Commit 0b982793 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-03-23 15:25:30 by simonmar]

document :def and :undef
parent 0f418257
......@@ -628,10 +628,55 @@ $ ghci -lm
<term><literal>:def</literal> <replaceable>name</replaceable> <replaceable>expr</replaceable></term>
<para>The command <literal>:def</literal>
<replaceable>expr</replaceable> defines a new GHCi command
implemented by the Haskell expression
<replaceable>expr</replaceable>, which must have type
<literal>String -> IO String</literal>. When
<replaceable>args</replaceable></literal> is typed at the
prompt, GHCi will run the expression
<replaceable>args</replaceable>)</literal>, take the
resulting <literal>String</literal>, and feed it back into
GHCi as a new sequence of commands. Separate commands in
the result must be separated by
<para>That's all a little confusing, so here's a few
examples. To start with, here's a new GHCi command which
doesn't take any arguments or produce any results, it just
outputs the current date & time:</para>
Prelude> let date _ = Time.getClockTime >>= print >> return ""
Prelude> :def date date
Prelude> :date
Fri Mar 23 15:16:40 GMT 2001
<para>Here's an example of a command that takes an argument.
It's a re-implementation of <literal>:cd</literal>:</para>
Prelude> let mycd d = Directory.setCurrentDirectory d >> return ""
Prelude> :def mycd mycd
Prelude> :mycd ..
<para>Or I could define a simple way to invoke
&ldquo;<literal>ghc --make Main</literal>&rdquo; in the
current directory:</para>
Prelude> :def make (\_ -> return ":! ghc --make Main")
......@@ -714,6 +759,16 @@ $ ghci -lm
<term><literal>:undef</literal> <replaceable>name</replaceable></term>
<para>Undefines the user-defined command
<replaceable>name</replaceable> (see <literal>:def</literal>
<term><literal>:unset</literal> <replaceable>option</replaceable>...</term>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment