Debugging partial functions by the rules

Simon Peyton-Jones simonpj at
Wed Nov 15 08:03:29 EST 2006

| Looks good! But that is deceiving: the assert was expanded before the rule
| fired, and refers to the rewrite rule source line (line 19), not the fromJust
| call site (line 12).  Now if we could just have the 'assert' token inserted
| into the AST before it was expanded, we'd be home and dry. Could this be done
| with TH? Or could we arrange for asserts in rewrite rules not to be expanded
| till later?

That's difficult.  Trouble is, the assert expansion happens right at the front, before any desugaring or program transformation.  But rewrite rules fire much, much later, in the simplifier.

It is, however, possible (or could be made possible) to answer the question "When this rule fires, what module am I compiling", and make that available in the RHS of the rule, by some magic incantation.

Harder would be "when this rule fires, what top-level function's RHS is being simplified?".  But even that is tricky, because it might be "lvl_4532", a function created by the simplifier itself.

The only solid way to connect to programmer-comprehensible stuff is by transforming the original, unadulterated source code, as Hat does, and as Jhc does, and as Simon and I are musing about doing.

Your idea is to do something cheap and cheerful, which is always a good plan.  But I don't see how to make it fly.

(The -O thing, and/or providing $currentLocation rather than just 'assert', seem easier.)


More information about the Glasgow-haskell-users mailing list