:info features

Claus Reinke claus.reinke at talk21.com
Thu Feb 5 14:07:40 EST 2009

>>    :info Show        -- See class definition only
>>    :instances Show   -- See instances of Show
> If you do not want to wait till this is implemented you can do it 
> yourself using ghci scripting.

Here's a first stab (ghci 6.8.3, using the :redir command from that tutorial),
filtering out lines beginning with "instance" until indentation level returns to

    Prelude> :{
    Prelude| :def infoNoInsts \x->return $ unlines
    Prelude| [":redir out :info "++x
    Prelude| ,"let noInsts [] = [];
    Prelude|       noInsts (l:ls) = if \"instance\" `Data.List.isPrefixOf` l
    Prelude|                        then noInsts $ dropWhile (Data.Char.isSpace . head) ls
    Prelude|                        else l:noInsts ls"
    Prelude| ,"putStr $ unlines $ noInsts $ lines out"]
    Prelude| :}
    Prelude> :infoNoInsts Show
    class Show a where
      showsPrec :: Int -> a -> ShowS
      show :: a -> String
      showList :: [a] -> ShowS
            -- Defined in GHC.Show
    Prelude> :infoNoInsts [] Maybe Int
    data [] a = [] | a : [a]        -- Defined in GHC.Base
    data Maybe a = Nothing | Just a         -- Defined in Data.Maybe
    data Int = GHC.Base.I# GHC.Prim.Int#    -- Defined in GHC.Base

> Details how to do it are in tutorial from Claus Reinke:
> http://www.haskell.org/pipermail/haskell-cafe/2007-September/032260.html
> Understanding all the possibilities and limitations of ghci scripting 
> may take a day or maybe even more. But once you are done with it you can 
> implement your :instances command and and something like 
> :infoWithoutInstances withing an hour at most. And it is more 
> interesting that you could do much more extensions like this easily if 
> you need them in the future.

Note that "understanding" is unlikely to mean "feel comfortable with"
here:-( the quoting and scope management are rather attrocious in
'ghciscript', and as others have pointed out, my tutorial is rather short
on explanations (you really need to work through the examples).

It does, however, afford you the means to prototype your ghci ideas
quickly, and to build yourself a library of useful definitions for working
with ghci. Please remember to share any interesting ideas/code at the 
ghci wiki page


(once haskell wiki access is resurrected)


More information about the Glasgow-haskell-users mailing list