Conversation

This project has been months in the making, but I am extremely pleased to say that my prototype delimited control-based effect system for Haskell now passes every one of my unit tests. (9 tests may not seem like much, but almost all of these test tricky edge cases!)
Image
9
254
This library is built on top of low-level primitive operations for capturing slices of the RTS stack that I’ve added in my branch of GHC. Combined with a focus on minimizing allocation, `eff` generates incredibly good code. Here’s what the Core and STG output usually looks like.
Image
Image
1
40
In `eff`, I have taken great care to ensure code that doesn’t manipulate continuations doesn’t have to pay for them: low-level support for continuations means no need to CPS the program, which cuts down on heap allocation enormously. `eff` stack-allocates as much as possible.
1
25
To minimize heap allocation and pointer indirections, `eff` uses the new UnliftedNewtypes extension internally to avoid boxing as much as possible. To keep the code manageable, pattern synonyms are used where I can be confident the boxing will be optimized away.
Image
Image
Image
2
23
`eff` follows a “pay only for what you use” philosophy: most common effects—including Reader, Error, State, and Writer—never capture the continuation even once. If you do use an effect that captures the continuation, `eff`’s internal state adapts to accommodate further captures.
1
22
The user-facing interface to `eff` is comparable to existing free monad-based encodings of extensible effects, and in some ways I think it’s actually simpler. None of the implementation complexity is visible to an end user of the library.
Image
2
25
`eff` supports full delimited continuations with late binding of effectful operations: a captured continuation can be resumed with a completely different set of handlers, as long as all the effects are still handled.
Image
2
26
`eff` is mostly working, but it is still only a prototype: • It only works on my modified fork of GHC. • The continuation primops need optimizing. • Support for IO exceptions and resource handling is 100% achievable but needs to be implemented. • Everything needs docs!
2
42
Nope! The name has been tentative since I started working on it, but a lot of the other obvious names are taken, and I haven’t come up with something better (yet). Suggestions welcome!
5
4