[project @ 2001-02-11 14:33:27 by simonmar]
authorsimonmar <unknown>
Sun, 11 Feb 2001 14:33:27 +0000 (14:33 +0000)
committersimonmar <unknown>
Sun, 11 Feb 2001 14:33:27 +0000 (14:33 +0000)
commit3be030c261124cfa5934b6a65e0c9fe097696cd7
tree8f12b52631ed4fc94ede8488b7ab2a349e699d44
parentcb13cd97bf6e0e8ec4661a9aced97f9fdac62a6e
[project @ 2001-02-11 14:33:27 by simonmar]
Experimental implementation of a bizarre, and probably not well
thought out, idea I had last week: making GHCi extensible, in Haskell.

Two new commands:

:def <name> <expr>
:undef <name>

:def defines a new command, :<name>, with the semantics that

(<expr> :: String -> IO String)

is run, passed the argument to :<name>, and the resulting string is
fed back through GHCi's command-line interpreter (\n may be used to
separate commands in the returned string).  <expr> is compiled once,
when the :def command is entered.

Simple example:

Prelude> :def date (\s -> Time.getClockTime >>= print >> return "")
Prelude> :date
Sun Feb 11 13:44:28 GMT 2001
Prelude>

Implementing built-in GHCi commands with macros:

Prelude> :def mycd (\s -> Directory.setCurrentDirectory s >> return "")
Prelude> :mycd /home/simonm
Prelude> :!ls
...

Define new functions from the command-line:

Prelude> :! echo "module Tmp where" >/tmp/Tmp.hs
Prelude> :def let (\s -> return (":! echo " ++ s ++ ">> /tmp/Tmp.hs\n:load /tmp/Tmp.hs"))
Prelude> :let x = 42
Compiling Tmp ... compilation IS required
Ok, modules loaded: Tmp.
Tmp> x
42
Tmp> :let y = x
Compiling Tmp ... compilation IS required
Ok, modules loaded: Tmp.
Tmp> y
42
Tmp>

I'm sure the possibilities are endless...
ghc/compiler/ghci/InteractiveUI.hs