GHCi should know about itself, so that .ghci can be portable
i've recently found myself writing .ghci files for ghc head which, with a few changes, can be made to work with 6.6.1 as well. then someone reported that they produce errors on his system (apparently, some people still have to use 6.4.1, for whatever reason). there are now two versions of the .ghci file: one for 6.4.1, one for 6.6.1 and later.
it would be useful if ghci could be queried about itself. since the query results need to be processed further, queries should be functions. i propose an implicitly loaded namespace GHCi. for such queries. examples:
GHCi.version :: [Int] -- version number
GHCi.info :: [(String,String)] -- the results of +RTS --info on the current ghci
GHCi.docdir :: String -- the result of --print-docdir
GHCi.libdir :: String -- the result of --print-libdir
GHCi.exists :: String -> Bool -- commands defined, flags available
GHCi.has :: String -> Bool -- features availabe
there are an increasing number of ghc options that provide information not easily available in ghci (calling ":!ghc --version" gives no guarantee of reaching the right version of ghc! using Config.cProjectVersion was not available in 6.4.1, and requires loading -package ghc, which might leave residues/instances for the rest of the session). all of those information flags should have ghci equivalents.
functions GHCi.exists and GHCi.has are inspired by established practice in vim: the former gives information about specific items (commands defined, flags accepted), the latter gives information about more general feature sets (debugger available? threads available?).
GHCi.exists "-fno-print-bind-result" -- false in 6.4.1
GHCi.exists ":edit" -- true from 6.6.1 on
GHCi.exists ":cmd" -- true from somewhere in 6.7.x onwards
GHCi.has "debugger" -- true from somewhere in 6.7.x onwards
no, we can't backpatch 6.4.1 or 6.6.1, but 6.8.1 will still be around when 7.x is in standard use, so the sooner the better.
(related to #1765 (closed), which was not by me;-)
Trac metadata
Trac field | Value |
---|---|
Version | 6.6.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | GHCi |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | claus.reinke@talk21.com |
Operating system | Unknown |
Architecture | Unknown |