Notes: 19th October 2026

Mon 19 October 2026

Filed under Posts

Tags weeknotes

I see I'm a bit behind here. Hello again. I've spent the last little while working on a parser for the surface language, and the structure of the elaborator and some of the machinery that entails. A lot of this has involved trying to remind myself how Idris 2 itself works, partly because it seems to make sense to borrow some code where appropriate, and partly because if I remember why we do things a certain way there, then maybe I can make some more informed decisions this time around.

The main thing I've noticed is: wow, it's grown to become complex, and probably more complex than it needs to be! For example, currently I'm looking at unbound implicits in the new elaborator - essentially that's where if we see a variable we don't know about in the type declaration (under some syntactic constraints) then we implicitly bind it. It's mostly a syntactic convenience, but can be a bit more than that if there's a lot of dependency in a type. Anyway, I was looking at the Idris 2 implementation for reference and trying to work out why the code was so complex, since it feels like a simple feature after all.

It turns out (to cut a long story short...) that a big reason for the complexity is because in Idris 2, rather than elaborating the surface language directly, there is a desugaring step that goes to an intermediate language called TTImp (for TT with implicits). At the start, that seemed like a good idea, because it'd keep the language I needed to elaborate smaller, and it's fairly obvious how most high level features are desugared. Unfortunately there are some big disadvantages:

  • Error messages are based on the desugared code, not the code you wrote, which can be confusing
  • Not all features have an immediately obvious desugaring. Interfaces, for example, translate into records, but there's a lot of work to do and it's not purely syntactic
  • As I've stumbled on recently, a lot of complexity creeps into the implementation.

In this case, the complexity arises because there is a construct in TTImp called IBindHere that says "I need you to bind the unbound implicits at this point" and because of the desugaring of some more complex structures, it's not always at the top of a type declaration.

Anyway I don't know if this ramble helped anyone bu myself, but I do keep finding this examples where, in the interests of making Idris 2 easier to write in the first place, it has become much harder to maintain now that it's grown.

I'd already decided to dispense with TTImp, and I'm even happier that I did now.


Comments


Edwin Brady © Edwin Brady Powered by Pelican and Twitter Bootstrap. Icons by Font Awesome and Font Awesome More