[Haskell-cafe] GHC-API: a few questions
mailing_list at istitutocolli.org
Sun Sep 2 10:09:11 EDT 2007
I'm trying to acquire some confidence with the GHC-API and I'm having
some problems, related to error handling, I seem not be able to solve.
Basically there are 3 functions to (interactively) compile/run
Haskell expressions: compileExpr, dyCompileExpr and runStmt.
The first 2 will return the value of the compiled expression, as a
Maybe HValue the first, and a Maybe Dynamic the second, while the
third can bind names and report them, or report exceptions.
But my problem is related to the first two.
I run expressions (string_expression) wrapped around some
let x = string_expression in take 2048 (show x)
to avoid infinite list or loops.
According to the documentation one should be able to control how error
messages are dealt with, by manipulation the GHC session's state.
One component of the session state, indeed, is the log_action which,
by default, prints errors and warnings to the standard error
Now, no matter what I do, I seem not to be able to change the
log_action to collect error messages and warnings. In any case
everything seem to be printed to standard error.
This way I can only collect exceptions raised by the compiler.
"Prelude.last: empty list" for
string_expression = "last "
But if my expression raises a type error, this is printed to stderr.
Like in the case of
string_expression = "last"
which would produce a
"No instance for (Show ([a] -> a))"
What am I doing wrong?
Thanks for your kind attentions.
ps: there are quite a lot of other questions I'd like to ask about
some programming techniques I've seen applied in GHC. For instance,
sometime a list of actions is given as a string, to be compiled to a
HValue which is written to a IORef. Running those actions is just a
matter of reading the IORef (you can see this in
compiler/ghci/InteractiveUIhs, when it comes to buffer management. For
instance: flushInterpBuffers). I ask to myself: Why? Just to amaze the
More information about the Haskell-Cafe