← All articles

A Filter You Can't Turn Off

Which language makes sense when a model writes the code, and why the winner isn't the one with the best filter but the one that won't let you skip it

18 min readprogramming-languagesfunctional-programmingrusthaskellartificial-intelligence

Machine-translated from Spanish. Read the original

ByFederico Sawady O'ConnorRagnagrok Academy

In Building or Pruning the Infinite I arrived at an idea I can't shake, that programming with a language model is generating and pruning. The model proposes code at a speed no person can match, and what matters is how good the filter is that decides which part of all that gets to stay.

If that's true, a very practical question comes up, one people ask me often. Which language should you work in?

The short answer is that it depends on how much of that filter the language gives you for free. The long answer is this article.

The criterion

When the one writing is a model, a language has to balance two things:

  • How well the model writes in that language. It depends mostly on how much code in that language it saw during training. It saw a huge amount of JavaScript and Python; much less Haskell.
  • How strong and how expensive the filter is. Which errors the compiler rejects before the program ever gets to run, and how long each turn of the loop “the model writes, the compiler complains, the model fixes” takes.

A language's most important filter is its type system, that is, the rules the compiler checks about which values can go where. A good type system lets you describe the problem in such a way that many incorrect programs simply can't be written. I wrote about that in Type Systems for Machines That Program.

By that criterion, the candidates look like this:

Language How well the model writes it How strong the filter is
Strict TypeScript Very well; it's the most fluent Weak: it has holes anything can slip through
Rust Well Strong out of the box, with visible exits
Scala 3 Confused Very strong, but optional
Haskell Less well The strongest of the general-purpose ones
Lean Not much It doesn't just check: it proves

TypeScript is JavaScript with types, and it's probably the language models write best today. The problem is that its type system has emergency exits—an any type that accepts anything, forced conversions the compiler doesn't check—and a model that gets stuck will use them. It can be hardened with automatic rules that ban those exits, validation of the data coming into the system and property tests. But each of those is a decision someone has to make and keep upholding.

At the other end is Lean, which isn't just a programming language but a proof assistant, which lets you prove mathematically that a program meets its specification. It makes sense for the small core where a mistake is unacceptable, not for the whole system.

The interesting game is played in the middle.

Scala has a very strong filter, but it's optional

Scala deserves a section of its own because, on paper, it's ideal. It's a language that runs on the Java virtual machine—which counts for a lot at banks and payment companies, which have everything built on it—and in version 3 it has almost everything you could ask for, such as types that describe the domain's data precisely, mechanisms for writing generic code, and libraries that let you carry types all the way to effects, that is, which functions can touch the outside world and which can't.

The problem shows up when the one writing is an agent:

  • The filter is convention, not law. Scala lets you write classic imperative code—null values, variables that change, exceptions, forced conversions, a println in the middle of a function that was supposed to be pure—and it compiles without complaint. When the model gets stuck, it falls back to that style, which is the one it has seen the most.
  • The generator is confused. Two quite different versions of the language coexist in the training data, along with two rival families of libraries for handling effects. The model mixes them up.
  • The filter is expensive. Scala compiles slowly, and every turn of the loop costs more.

You can make it work by closing the doors by hand. That means using Scala 3 only, turning the compiler's warnings into errors, adding tools that ban nulls, exceptions and forced conversions, and picking a single family of libraries and writing that down in the agent's instructions.

But that's where the difference that gives this article its title lies. Scala wins on expressiveness. Rust wins because its filter comes switched on, and no option turns off the check for cases or the one for absent values. Its exits (unsafe and unwrap) compile with no options, but they're visible words, closed with one attribute or a rule in Clippy, the automatic reviewer that ships with Rust. And if the one programming is a model—which will take any shortcut the language allows—a filter you can't turn off is worth more than a better one you have to remember to turn on.

Correction (November 25, 2026). The first version titled this section "Scala has the best filter", when the table and the Haskell section give that place to Haskell. It also said, here and in the table, that Rust's filter can't be switched off, but the repo shows that unwrap and unsafe compile with bare rustc. What can't be turned off are the checks that come out of the box, and those exits are closed with #![forbid(unsafe_code)] and a Clippy rule, so the conclusion holds with that nuance. I found it in a review of the series.

The repo writes the same four small mistakes in the four languages and compiles them with no options at all. In parentheses is the one-word exit each language leaves open. This is what each compiler does out of the box:

Mistake Haskell Rust Scala 3 TypeScript
1. A case nobody handles compiles without a warning rejects warns compiles
2. A value that may be missing, used as if it were there rejects (head warns) rejects (unwrap() compiles) rejects (.get or null compile) compiles
3. An effect inside a calculation rejects (unsafePerformIO compiles) compiles compiles compiles
4. A value from outside forced into a type unsafeCoerce compiles unsafe { transmute } compiles asInstanceOf compiles and fails at run time as compiles and carries on with undefined

What interests me most is the Rust column, which rejects mistakes 1 and 2 without anyone configuring anything, and whose exits are visible words. TypeScript with --strict also rejects 1 and 2, but lets ! and as through. With everything closed by hand (the compiler options plus Clippy, WartRemover or typescript-eslint, which are automatic reviewers), the mistakes and their exits all get rejected. The only thing no option closes is mistake 3 outside Haskell.

Rust takes Haskell's lessons and keeps control of memory

Rust is an imperative language, from the family of C and C++, designed for programs where fine control over memory and performance matters. And yet, among widely used imperative languages, it's the one that most resembles Haskell.

The key is how it handles state. Haskell, being a functional language, simply has no variables that change, and that wipes out a huge number of errors at the root. Rust does let you change data, but with a rule the compiler enforces, which says that a piece of data can have many readers or a single writer, never both at once. Nobody can change data on you while you're looking at it, unless its type says so, like Cell, RefCell or Mutex, which let it change even while others are reading it (what Rust calls interior mutability).

Correction (November 25, 2026). The first version said the rule has no exceptions and that nobody can change data on you while you're looking at it. That's not so, because Cell, RefCell and Mutex let data change even while others are reading it. The exception is written in the type, so what follows holds for data that doesn't announce it. I found it in a review of the series.

Haskell eliminates state; Rust makes it private. Both end up in the same place. You can understand a piece of the program by looking only at that piece, without wondering what other part might be touching it behind your back.

It inherited much more from Haskell:

  • There's no “null.” Instead of any value possibly turning out empty by surprise, Rust has a type that says explicitly “there may or may not be a value here,” and it forces you to handle both cases. The same goes for errors, where an operation that can fail says so in its type, instead of throwing an exception nobody expected.
  • Every case gets covered. When the code distinguishes between several possibilities, the compiler checks that you didn't forget any of them.
  • Everything is immutable unless you say otherwise.
  • Iterators are lazy, so Hughes's idea of generating the infinite and pruning it is right there, in almost the same shape:
take 3 . filter esPrimo $ [2..]            -- [2,3,5]
(2..).filter(|&n| es_primo(n)).take(3)     // [2, 3, 5]

The two lines say the same thing, which is taking all the numbers from 2 onward, keeping the primes (esPrimo and es_primo are Spanish for is prime) and stopping at the third one. An infinite generator, a filter, and something that cuts it off.

What Rust lacks is, above all, one thing. In Haskell, a function's type says whether it can touch the outside world—read a file, query a database, check the time. In Rust, it doesn't. Any function can do anything. There's an architectural fix for that, which I describe in First the Filter, Then the Generator, but the language doesn't give it to you on its own.

Rust is what happens when someone takes Haskell's lessons seriously without giving up control over memory.

What the evidence says

That Rust is “safer” is something people repeat a lot. It's worth separating what has been shown from what hasn't.

On memory safety, the evidence is strong. In C and C++, the programmer manages memory by hand, and the mistakes made doing it—writing past the end of a reserved space, using memory that has already been freed—are the classic source of security holes. Google has spent years writing Android's new code in languages that prevent those mistakes, mostly Rust. Memory vulnerabilities went from 76% of the total in 2019 to under 20% in 2025, and in the Rust code they found about a thousand times fewer per line of code than in the C and C++. There was one near miss, a memory bug in a part of the Rust code marked unsafe—the blocks where the programmer tells the compiler “trust me, I've got this”—which another of the system's defenses made harmless before it reached users. Google tells the story precisely to insist that no single defense is enough on its own.

The formal guarantee exists, with limits. A research team (RustBelt, 2018) proved mathematically, using a proof assistant, that in a formal model of a realistic subset of Rust the rules of the type system really do guarantee what they promise, even when there are unsafe blocks, as long as those blocks honor their contract. Another study (Qin et al., 2020) analyzed 70 memory bugs and 100 concurrency bugs in real Rust programs. Every one of the memory bugs went through unsafe blocks. And the concurrency bugs are where the limit shows, because Rust prevents two threads from writing the same data at the same time, but it doesn't prevent a thread from getting stuck forever waiting for another, and that was the problem in more than half the cases.

Correction (November 25, 2026). The first version said that in Android's Rust code they found a thousand times fewer memory vulnerabilities, and that RustBelt proved the guarantee for Rust. The Android figure is a density, vulnerabilities per million lines, not a count. RustBelt proves it for a small language that models a realistic subset of Rust, not for the whole language or its compiler. The evidence is still strong, and I found it in a review of the series.

On business correctness, the evidence is weak. Google also measured that changes in Rust get rolled back about four times less often and spend 25% less time in review. It's a good sign, but it isn't an experiment, so we don't know how much of it is down to the language and how much to the teams that chose it. The most cited study on languages and number of bugs (Ray et al., 2014) found small effects, and when another team repeated it more carefully (Berger et al., 2019), most of those effects disappeared.

In Building or Pruning the Infinite I talked about the conservation laws of physics, rules that hold even when you're not looking. Rust guarantees by law a small set of things (memory, and that two threads don't write the same thing at once). It's a real guarantee, and it's worth a lot. But your business rules—that a code can't be redeemed twice, that a balance adds up—don't come included. You have to write them into types and tests. Rust gives you a floor, not a ceiling.

What about Haskell?

If the question is which filter is stronger, Haskell wins on what matters most for modeling a business's rules. Since each function's type says whether it can touch the world, you know without reading it that a calculation function isn't going to write to the database behind your back. Reasoning with equalities actually works, which means that if two expressions are equal, you can replace one with the other anywhere. And there are tools to go further still, all the way to proving properties of the code.

But its floor, out of the box, has more holes than Rust's:

  • The library that's loaded by default includes functions that blow up on certain values, like head, which asks for the first element of a list and fails if the list is empty.
  • If the code doesn't cover every possible case, it compiles anyway. It doesn't even warn you unless the -Wall option is on, which projects created with cabal have by default.
  • A program that never finishes can have any type, so a type doesn't guarantee there will be a result.
  • Lazy evaluation, so useful for generating the infinite, sometimes piles up pending computations and eats memory in ways that are hard to predict.
  • And there's a back door for doing effects where you shouldn't.

Correction (November 2, 2026). The first version said the compiler warns you when a case is missing. With no options, GHC 9.12 compiles it without any warning; the warning shows up with -W or -Wall. I found it while turning the article into code, because the repo compiles each mistake with and without those options.

As for evidence, there are serious companies using Haskell in production—an international bank, Meta's anti-abuse system, a fintech with millions of lines of code—but there's nothing comparable to the Android measurement.

The good news is that those holes can be closed with compiler options that turn those warnings into errors and flag the dangerous functions, and with alternative libraries that leave them out. With that you get a floor close to Rust's and a considerably higher ceiling.

Is it worth it? For us, yes, for the core of the business, which is the part where the rules that can't be broken live. Upholding that filter is exactly the craft of Fidel, my business partner. And a strict compiler with good error messages has an advantage that isn't obvious at first glance, which is that it turns the model's lower fluency into more turns of the loop, not more bugs. The model gets it wrong more often, but the compiler stops it every time. For the rest—the interface, integration with other systems, whatever depends on a large ecosystem of libraries—Rust or TypeScript.

Not one language, then, but an architecture, where each part of the system goes in the language whose filter suits it.

Assembly, the limiting case

To really put the idea to the test, it's worth going to the extreme.

Assembly is the machine's own language, instruction by instruction (move this number into this register, add these two, jump to that address). It has no filter whatsoever. Any sequence of instructions is valid, and nothing tells the address of a piece of data apart from any other number. It's the naked machine John Backus criticized in 1977, when he received the Turing Award, in a lecture that is practically the founding charter of functional programming. If a language model generates assembly, there's nothing to prune it.

And yet assembly is also where automated search already beats people. The difference is whether there's something to prune with:

  • Proven compilers. CompCert is a C compiler proven mathematically correct, which means the assembly it produces does exactly what the original program said. There's similar work for other languages, and the seL4 operating system was verified all the way down to machine code.
  • Types all the way down. Since the late nineties there has been research into carrying types all the way down to assembly, and into having a compiled program travel with a proof that it follows certain rules, which whoever receives it can check without trusting whoever compiled it.
  • Generating and pruning without people. STOKE (Schkufza, Sharma and Aiken, 2013) looks for faster versions of a program by trying random variants—sometimes accepting a worse one so it doesn't get stuck, with the same temperature math I described in Building or Pruning the Infinite—and then proves that the version it found is equivalent to the original. DeepMind's AlphaDev (2023), using a different search technique—reinforcement learning—found faster sorting routines that are now in one of the most widely used C++ standard libraries.

Assembly is the limiting case of the whole idea. Without a filter, it's the worst place for a language model. With a way to prove the result is correct, it's the place where generating and pruning already works better than a person. What decides it isn't the level of the language, but whether there's something to prune with.

What you choose when you choose a language

A language model is, as I put it in Bricoleurs and Planners, a tireless bricoleur, with a well-known weakness. It overgeneralizes, takes shortcuts, finds patterns that aren't there. That's why choosing a language is no longer a matter of taste or fashion. It's deciding how much of the pruning you hand off to the compiler and how much you'll have to do yourself, by reading.

And if the honest answer is that you won't be able to read everything—because nobody can read everything a model generates—then you'd better have the pruning done by something that doesn't get tired, doesn't get distracted, and can't be turned off.


References

  • Hughes, J. (1989). Why Functional Programming Matters. The Computer Journal, 32(2). DOI
  • Backus, J. (1978). Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs. Communications of the ACM, 21(8). DOI
  • Vander Stoep, J. (2025). Rust in Android: move fast and fix things. Google Security Blog. Article
  • Vander Stoep, J. & Rebert, A. (2024). Eliminating Memory Safety Vulnerabilities at the Source. Google Security Blog. Article
  • Jung, R., Jourdan, J.-H., Krebbers, R. & Dreyer, D. (2018). RustBelt: Securing the Foundations of the Rust Programming Language. POPL 2018. DOI
  • Qin, B., Chen, Y., Yu, Z., Song, L. & Zhang, Y. (2020). Understanding Memory and Thread Safety Practices and Issues in Real-World Rust Programs. PLDI 2020. DOI
  • Ray, B., Posnett, D., Filkov, V. & Devanbu, P. (2014). A Large Scale Study of Programming Languages and Code Quality in GitHub. FSE 2014. DOI
  • Berger, E. D., Hollenbeck, C., Maj, P., Vitek, O. & Vitek, J. (2019). On the Impact of Programming Languages on Code Quality: A Reproduction Study. ACM TOPLAS, 41(4). DOI
  • Leroy, X. (2009). Formal Verification of a Realistic Compiler. Communications of the ACM, 52(7). DOI
  • Kumar, R., Myreen, M. O., Norrish, M. & Owens, S. (2014). CakeML: A Verified Implementation of ML. POPL 2014. DOI
  • Sewell, T., Myreen, M. O. & Klein, G. (2013). Translation Validation for a Verified OS Kernel. PLDI 2013. DOI
  • Morrisett, G., Walker, D., Crary, K. & Glew, N. (1998). From System F to Typed Assembly Language. POPL 1998. DOI
  • Necula, G. C. (1997). Proof-Carrying Code. POPL 1997. DOI
  • Schkufza, E., Sharma, R. & Aiken, A. (2013). Stochastic Superoptimization. ASPLOS 2013. DOI
  • Mankowitz, D. J. et al. (2023). Faster sorting algorithms discovered using deep reinforcement learning. Nature, 618. DOI
The code

Everything this article claims, in code that runs. Clone it, break it, open an issue.

Ragnagrok/a-filter-you-cant-turn-off
Support the blog

If this article was useful to you, you can sponsor the blog on GitHub. It helps me keep writing.