Effect Systems Vs. Print Debugging: a Pragmatic Solution
Posted4 months agoActive3 months ago
blog.flix.devTechstory
calmmixed
Debate
60/100
Programming LanguagesEffect SystemsDebugging
Key topics
Programming Languages
Effect Systems
Debugging
The Flix programming language implements an effect system that allows for print debugging while maintaining purity, sparking discussion on the trade-offs between purity and practicality.
Snapshot generated from the HN discussion
Discussion Activity
Very active discussionFirst comment
3d
Peak period
32
60-72h
Avg / period
11.5
Comment distribution46 data points
Loading chart...
Based on 46 loaded comments
Key moments
- 01Story posted
Sep 22, 2025 at 1:54 PM EDT
4 months ago
Step 01 - 02First comment
Sep 25, 2025 at 8:46 AM EDT
3d after posting
Step 02 - 03Peak activity
32 comments in 60-72h
Hottest window of the conversation
Step 03 - 04Latest activity
Sep 27, 2025 at 2:11 AM EDT
3 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45337059Type: storyLast synced: 11/20/2025, 5:20:53 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
Either way, extremely well explained both in motivate and implementation!
It already is, kinda. In my practice very often you have global singleton values that are either defined as static variables, or passed as arguments to nearly all functions in a module. Since implicit presence of `Debug` effect is already a compilation parameter, it could be generalized to support any sets of implicit effects. Thus you might design a module that has implicit Logger and Database effects in all its functions.
Logging does seem like a very similar case to debugging, only that you expect to leave it on in production. On the other hand an implicit Database effect kind of defeat the point of an effect system.
I think the key is that Debug and Logger effects don't really affect the rest of the code - if you remove all debug/log statements, the only thing that changes is the debug/log output (and slightly faster execution probably).
In a lot of logging systems, debug is one of the common levels of logging. I'm not even convinced that the term "debug" is unambiguous to clearly refer to something that's not a subset logging. Presumably the difference is intended to mean things printed that are unconditionally going to stdout rather than into some system that might change the output location and filter/annotate things, but I have to imagine that it might just make more sense not to have separate models for them at all
Perhaps there is two or three more, but I do think this is a finite set that we can write a language around and just sort of consider them "ambient effects". While metrics and logging are nominally impure, in that they are certainly mutations, if you can't read the logs or the metrics without an effect, you still retain the really important aspect of purity, which is that the pure code can't cause a change that is observable by that or other code, with the very specific exception of the logging stream and metrics.
I wouldn't be quite ready to put all my chips on this, but I think "the inability to create changes that can be witnessed" is actually the true goal, not "the inability to create changes" with no qualifications. Pure code already necessarily creates changes in a system, the key is that while the CPU registers may change and other parts of the system may mutate, the code can't witness those changes and conditionalize future execution on it. All effects-based systems have already agreed that there are things that are mutations in something real in the physical world they aren't going to consider effects, adding a couple more categories is not going from 0 to 1 but 12 to 15. It's not a strict purity question but a cost/benefits question.
It occurs to me as I type this that a really ambitious language with a strong enough type system might even be able to turn this into a completely safe proposition, allowing users to declare effects with some sort of very safe "sink" associated with them that the type system checks can not escape out into the rest of the code in any visible way and constraining the visibility somewhere that is contained in the conventional effects system. All these things I'm talking about here and in the blog post are taking the form of values that simply disappear into the ether from the point of view of the creating function. I'd like the language to make it easy to query a function for which ambient effects it uses (as a development-time operation, not a run-time one), and I think that would clean up most of the rest of the practical problems.
But I think in concept that maybe that's pretty close to the concept. Input from IO is arguably the definition of impure that we care about. But not all forms of Output are necessarily radioactive waste for purity. We might be able in practice to give ourselves a bit more wiggle room on that side without breaking all the benefits of purity, and gain substantial practical utility for a very, very small loss in theory. With some careful thought it's even possible the theory loss could be either "minimized or eliminated" or "strongly characterized and constrained". I don't know enough about the language in question to know what is in it, but a language that had first-class messaging of some sort ought to be able to define a form of output that is "you can send this message to this target any time you want without breaking purity", and the the code for the thing receiving the message could still itself be constrained by the effects system. (You could conceivably go so far as to insist that the resulting "exception handlers" rigidly form a tree that grounds out into code that uses none of these implicit handlers, though my gut says that will probably end up being more trouble than it is worth.)
https://hackage-content.haskell.org/package/bluefin-0.0.17.1...
It's proper (but goofy) to pass in a `logger` object to every function, but the practicality of plumbing a "logger" everywhere is disgusting. There's a ton of value to be able to "capture" what was logged by a function, but as you mentioned with "metrics", the invasiveness of plumbing a metrics object "through" your code is really gross.
Maybe a straw man syntax like:
...like a puzzle piece, if the container (parent object) wants to "attach" to the exported interface, it can kindof dependency injection, otherwise logs and metrics might fly off into the void.At some point you're composing your pure functions and _have_ to call them by some effectful function (otherwise they're never executed or you're doing computations that aren't consumed by anything).
The only sane alternative is to have a debug effectful variant where you turn off these checks. But then why would `stdout` debugging fine, and not say writing to a different stream or file?
[1] https://hackage.haskell.org/package/base-4.21.0.0/docs/Debug...
This is bc of non strict eval in Haskell, but still the core is that the lang is designed to not eval stuff when it’s not necessary.
Imagine saying that certain memory stores are allowed to cross a memory barrier operation, you'd completely lose the ability to reason about concurrency around those stores.
If printing- or logging statements have no effect, the compiler might reorder them or even remove them.
I'm curious what other languages are trying to achieve such?
- https://effekt-lang.org/
- https://koka-lang.github.io/
- https://www.unison-lang.org/
- https://antelang.org/
1. Initially there was no way to do effects in Haskell, everything was pure.
2. Then it was realized that IO can be modeled with monads, so the IO type and do notation were added.
3. Gradual realization that monads can be used to also constrain effects, ie you can construct a type of "stateful computations" that can read and write to a specific state, but not touch other states or write to disk or something.
4. Monad transformers are invented, which allow stacking monads on top of eachother to support multiple effects. Together with type classes, this gets us pretty close to extensible effects (the approach used in Flix, if I understand it correctly). So for example you can express that your function needs to write to a log and may exit early with an error message with the constraints `(MonadWriter w m, MonadError e m) => ... -> m resultType`, and you can then use monad transformers to build a stack that provides both of these effects.
5. Monad transformers have some issues though: they affect performance significantly and the interaction between effects is tricky to reason about. So an alternative is sought and found in extensible effects. The initial proposals were, iirc, based on free monads, but those aren't great for performance either, so ever since there has been a whole zoo of different effects and handlers implementations that all make different trade-offs and compromises, of which I think the `effectful` library is now the de facto default, and I think what it offers is quite similar to the Flix language's effect system (I'm not sure on what finer points it differs).
https://hackage.haskell.org/package/effectful#what-about-mtl
You can see my talk "A History of Effect Systems" for a synopsys of the history. I gave it at Zurihac this year. It's very close to the history you gave (though I think point 1 is not right: Haskell always had a way to do IO)
https://www.youtube.com/watch?v=RsTuy1jXQ6Y
[1] - https://koka-lang.github.io/koka/doc/index.html
The team can’t seem to make up its minds of the language is intended for high performance or not. They talk about the importance of purity for automatic optimizations but in the real world there’s all sorts of practical reasons for needing to debug production compiled code (eg imagine something like a browser and you’re trying to figure out some weird behavior that’s difficult to catch in a debugger but too slow to reproduce in a debug build or even not reproducible due to different timings resulting in different race conditions)
Also blaming the users of your language for your language not being able to meet their needs isn’t a good look. It suggests the language is probably attracting the wrong users or positioning itself incorrectly in the market place.
For systems in production, we have the `Logger` effect and associated handlers.
And yes, Rust doesn’t have an effect system yet, but others have mentioned Haskell and how it handles tracing and logging and the limitations of effect systems interplaying with such things.
To be me, the interesting question is: What happens when you lie to the type (and effect or ownership) system?
No, and there's no indication that automatic parallelization is at all worth the effort vs having the author explicitly annotate which things need parallelization (e.g. Rayon is drop-in for many tasks where you know you'll need it). Otherwise you're at the mercy of heuristics baked into the language which in practice never work out well and also slow down the non multithreaded use-cases.
> To be me, the interesting question is: What happens when you lie to the type (and effect or ownership) system?
As others have said, just having the print get elided if the operation gets optimized out would be fine. That's what Haskell does. It's a weird choice to look at the challenges of effect systems and conclude the effect system idea is perfect it's the programmers who are wrong and not that the effect system has gaps that can't be addressed and solve it in other less surprising ways.
> They talk about the importance of purity for automatic optimizations but in the real world there’s all sorts of practical reasons for needing to debug production compiled code
I imagine they're talking about their defaults. One can commonly reconfigure how different build profiles work.
> Also blaming the users of your language for your language not being able to meet their needs isn’t a good look.
Isn't that what the whole post is about though? They even say the following.
> Returning to earth: we may be academics, but we are trying to build a real programming language. That means listening to our users and that means we have to support print debugging. The question is how?
Things like this - they're painting users of programming languages as the ones being unreasonable.
> I imagine they're talking about their defaults. One can commonly reconfigure how different build profiles work.
From the article:
> We don’t want published packages to (a) lie to the type and effect system, or (b) contain print debugging statements > As a result, using dprintln in production mode causes a compilation error.
There is no documentation about the existence of build profiles or how they might work. I think you're reading too charitably.
Do you have some specific special effects in mind?
something I'd sometimes like to do when I'm profiling complex code will be to have an (essentially) global variable tracking the sum of how long a function took to execute over all invocations.
I am guessing that mutating the global counter would count as an effect, and I wouldn't really want to add the effect all the way through the call graph. I think this is something where the handling ought to be similar to how you're handling Debug.
It's not just print debugging. It's also logging. Oh, you want/have to add useful/required logging? Good luck refactoring your entire code to thread IO everywhere.