capabilities of GHC API

Frederik Eaton frederik at a5.repetae.net
Sat May 19 07:43:16 EDT 2007


Hello,

I think what I'm trying to do is too ambitious, but I thought I would
ask to see if it is possible. It seems like there is no easy way to do
it, given what I've seen of the GHC API.

I would like to have a function, say it is called "this", which has
the following effect in ghci

> let n = 2 in this
> n
2

In other words, it captures all the variables which are in scope, and
adds them to the GHCi environment. Somebody helpful will probably say
"But you can just write 'let n = 2'!", but that is not the aim. There
are several aims. One is to be able to look at the variables inside a
function which one is trying to debug, then inserting 'this' will
cause them to be in scope, I think that would be useful. A more
important aim is to be able to use existentially quantified variables
easily. Currently I can do:

> reifyIntegral 5 (\n -> print $ reflectNum n)
5

but how can I get GHCi to have an 'n' binding which is inside the
function? Clearly just returning 'n' will not work:

> reifyIntegral 5 id

<interactive>:1:0:
    Inferred type is less polymorphic than expected
...

This is what I am thinking of doing, but as I said it seems ambitious. 
There are several easier things one could think of:

> let n = 2 in bind "n" n
> n 
2 

If it were possible to add bindings to the GHCi bindings list, then
this would be easy. Is it possible? The documentation doesn't seem to
mention such a capability.

Also, probably another useful feature would be to combine 'this' with
something in the IO monad:

> withProgName "blah" thisIO
> getProgName
"blah"

So, are these things currently possible? Planned? Have the functions I
describe been implemented already? I think there is a GHCi debugger in
the works, so maybe functionality like this will be part of it, I
didn't want to start something on my own if that is the case...

Many thanks,

Frederik

-- 
http://ofb.net/~frederik/


More information about the Glasgow-haskell-users mailing list