Using extcore

Tim Chevalier catamorphism at gmail.com
Thu Nov 3 00:53:25 CET 2011


On Wed, Nov 2, 2011 at 8:19 AM, Knut Halvor Skrede <khskrede at gmail.com> wrote:
> Hi,
>
> I'm working on a project where I need to dump Core to an alternative format.
> So I'm wondering if it is possible to use the ghc api to compile haskell to
> core,
> and then use the extcore package to make a representation of the result as a
> Core module. That way I could simply traverse it and make whatever
> representation
> necessary, based on the Core language definition. It seems to me like the
> extcore
> package is only for parsing external-core files? I don't want to have to
> dump core to
> a file, then parse it back. I was unable to find any documentation on how to
> do this.

Hi Knut --

If I may ask, why don't you want to dump ext-core to a text file? I
can understand if the answer is performance reasons, but I would
strongly encourage you to start with this route in order to get a
prototype working. It's much easier; at least the last time I tried to
use it (which was over a year ago), the GHC API was quite imperative,
and when you're just starting your implementation, it's easier not to
worry about that sort of thing. If you go this route, you should be
able to just use the extcore library out of the box. There is some
minimal documentation as a README inside the extcore package (the
version that's on hackage); if you have any questions that it doesn't
answer, as is likely, feel free to ask me and CC the ghc-users mailing
list (so that the answer will be public and searchable). Once you have
a prototype working, if you find that intermediate file
reading/parsing is a bottleneck, you can change what you have to use
the API to generate Core in-process instead of generating an
intermediate file with -fext-core.

If you want to just use the GHC API from the start, I can't be as
helpful there, because I haven't played with that part of GHC in a
long time, and it's known to change quickly. People on the ghc-users
mailing list may be able to help. Depending on what you want to do,
you may not need to use the extcore library at all if you use the API.
You can generate a Core module, as well as typecheck it (using Core
Lint) only using API functions that are documented in the GHC API
documentation. If you did need to use the extcore library together
with the API, you would need to use one of the functions in the
MkExternalCore module (which should also be part of the API) to
explicitly convert GHC's internal Core into external Core. I haven't
done this, but there's no reason in principle why it wouldn't work. If
you do get results this way, and feel like helping out, you could add
your procedure to the wiki: http://hackage.haskell.org/trac/ghc/wiki

If you have any followup questions, please reply to me and CC the
mailing list, as I don't always read the mailing list, but it's also
good if replies are on the record.

Cheers,
Tim


-- 
Tim Chevalier * http://catamorphism.org/ * Often in error, never in doubt
“I cannot hide my anger to spare you guilt, nor hurt feelings, nor
answering anger; for to do so insults and trivializes all our efforts.
Guilt is not a response to anger; it is a response to one’s own
actions or lack of action.” -- Audre Lorde



More information about the Glasgow-haskell-users mailing list