:def and ghci command output

Claus Reinke claus.reinke at talk21.com
Thu Aug 23 15:37:05 EDT 2007

ghci's :def takes a 'String -> IO String' and converts it into a ghci command.
this makes it possible to pass a command parameter to a haskell function, 
and to interpret the result of the call as a ghci command.

that is nice, but how do i get access to the command's output? that is, 
i'd like to run a ghci command, and capture its ouput as a haskell String, 
eg, to pass it on to another ghci command, or to a haskell function.

perhaps something simple, like an additional ghci top-level binding:

    GHCi.cmd :: String -> IO String

so that i could write things like

    let doSomething output = ..
    :def mymodules \_->GHCi.cmd ":show modules" >>= doSomething

or a way to compose ghci commands, so that i could write

    :def doSomething \output->..
    :def mymodules \_->return ":show modules :>>= :doSomething"

would that be difficult to provide?


More information about the Glasgow-haskell-users mailing list