[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...