Core questions

Claus Reinke claus.reinke at
Fri Jan 30 17:52:00 EST 2009

>Core types (in particular CoreExpr) are not instances of Show. They are
>instances of Outputable, which allows them to be pretty printed.
>However, this pretty printing is good to view the structure of the
>expression that the CoreExpr represents, but doesn't show the structure
>of the CoreExpr itself.

Not sure how practical this would be, but to get an idea of
the internal structure: if you can derive the SYB classes for
the Core types (which would generally be useful if you do lots
of traversals), you can easily define a generic show operation,
which would give you a lot of control over what kind of output
you'd like.

There is an example here:
    look for the showData code - straighforward base plus lots
    of exceptions to avoid some ideosyncrasies of GHC's internal
    representations (in particular, don't try to traverse parts of
    the structure that haven't been filled yet)

example output here

hmm, I need to update that wiki page and the syb-utils package
page - the code has moved from there, to the syb and ghc-syb
packages, with proper maintainers. In particular, check the use
of standalone deriving to get the SYB class instances for GHC 
API types in package ghc-syb:

Iirc, the syb instances for Core were not included, if that hasn't 
changed yet, it would be a useful addition (for an old first stab, 
see the link at the bottom of that wiki page, CoreSynTraverse).


More information about the Glasgow-haskell-users mailing list