Alright I have a present for you all
I built a compiler that properly compiles lambda sets. The key insight is making sure to solve the type of lambda captures, transitively
See this example that solves a long-standing lambda set bug and enables effect interpreters in my compiler
The issue it solves is https://github.com/roc-lang/roc/issues/5464
If you want to study the source code, which is quite small but many passes, it is here https://github.com/ayazhafiz/cor/tree/base/experiments/lss
This is a proper monomorphizing compiler. I don't emit machine code or anything like that but the low-level IR pass is first-order and is trivial to compile to C or asm
Holy shit
Sam Mohr said:
Holy shit
Well said
Wait, so we don't need type erasure, do we??
If that's the case, I'd be happy to help with the translation of this work to the Roc compiler! Super exciting
Likewise, if there is anything we need on the platform side, like updating Brendan's POC I'm happy to help too.
omg omg omg
THIS IS THE BEST NEWS!!!!!!!
:star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck::star_struck:
I can't wait for when this lands in Roc! Will unlock so much stuff!!!
I can't wait for true async effect interpreters
Also should unblocks some random complex code like my sqlite improvements for basic-webserver and the better version of encode and decode.
There's a nice long list of really awesome things this should enable. I'm so excited to hear this news. Thank you Ayaz for sharing :grinning_face_with_smiling_eyes:
I've also partially implemented type erasure, as needed for Map2 - Map2 example here
quick note - I'm gonna take on the implementation of this!
Infinitely excited :laughing:
Let’s gooo
I was going to implement part of this in the Roc codebase the past couple days but I figured it would probably be a better use of my time to describe the implementation in significant detail, so that it can be discussed and hopefully easy for anyone to contribute to.
Here's a doc with the compilation process in significant detail - it's the same code as I shared before, but this time well-annotated (PR, doc). Please let comments/critiques/let me know where I'm using confusing language/what could be more clear/etc, I will address them.
I'll get to the remaining detailed sections on function lifting, function solving, and function specialization tonight and in the next few days.
Of note, I still think that switching to have all recursive types required to be nominal would make much of this simpler and more efficient in the long term. See https://github.com/roc-lang/rfcs/blob/ayaz/compile-with-lambda-sets/0102-compiling-lambda-sets.md
Last updated: Jul 06 2025 at 12:14 UTC