Cannot override ghci builtin commands with :def[!]
In cabal we have a feature called "cabal repl" where it loads ghci with all the appropriate flags for the package or sandbox.
One of the nice things we want to do is extend the :reload
(and related :add
, :load
) so that it calls out to cabal
to run any pre-processors (e.g. hsc2hs, happy, alex etc).
Unfortunately the :def!
command does not override builtin ghc commands. It looks like it works (:def
reports the thing) but then the builtin command is still used, e.g.:
:def! reload (\_ -> print "yay" >> return "")
:def
the following macros are defined:
reload
:reload
Ok, modules loaded: none.
Related to this overriding, is that we also want a way to run the original (the builtin). Technically speaking it's possible using :undef
, but then it's rather tricky to define again. You have to do something like define reload to call out to cabal, :undef reload
, :reload
, :def reload ...
. The tricky part is that last, we have to tie the knot, because that is the definition of :reload
so it has to be able to access it's own code, tricky but not impossible (can load it from a file, but ugly).
So ideally we'd have something like :builtin [cmd] [args]
that bypasses macros and executes the builtin command. Then we could define:
:def! reload :! cabal repl --reload ${other_stuff_here}
:builtin :reload
And similarly for the others :add
, :load
etc.
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.3 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | GHCi |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |