The Web’s Dirty Secret: Jane Street’s Bonsai Exposes the Functional Programming Fantasy

You’ve been told functional programming is the future. Pure, declarative, mathematically sound. No side effects, no mutable state, no surprises. Just beautiful, composable logic that scales like a dream.

Then you try to run it in a browser.

And suddenly you’re building a trampoline.

Not a metaphorical trampoline. A literal userland trampoline — a hacky piece of code that manually unrolls function calls because the browser’s JavaScript just won’t do tail call optimization. It’s like bringing a Ferrari to a dirt road and spending the afternoon building a bridge out of twigs and hope.

That’s exactly what Jane Street, the famously secretive, ludicrously profitable trading firm, had to do with Bonsai — their pure functional UI library for the web.

Let that sink in.

One of the most elite engineering organizations on the planet — a firm that writes its own hardware, its own operating system, its own language — looked at the web and said: “We’ll force our OCaml purity onto this mess, even if we have to break the laws of the platform to do it.”

And they broke them. Elegantly, but unmistakably.

Bonsai is beautiful. It’s a declarative, functional-reactive UI library built on top of Jane Street’s own OCaml-to-JavaScript compiler (JSOO). The code is clean, the architecture is principled, and the documentation is a love letter to monads and applicative functors.

But the comments on the GitHub repo tell a different story.

“JSOO does not have tail call optimization.”

Translation: The functional core of Bonsai — which relies on recursion and composition — can’t safely run in the browser without a manual workaround. So they built a userland trampoline to hand-hold the call stack, because the browser simply refuses to play along with functional purity.

“This would have been cool back in 2014.”

Ouch. The web moves fast. Bonsai’s approach is a decade-old dream that never quite landed.

And yet, the faithful still believe. Believe that if we just try harder, if we just write more pure functions, if we just compile harder, the browser will eventually bend to our will.

It won’t.

The browser is not a functional programming environment. It never was. And no amount of OCaml wizardry will change that.

The web is imperative. It’s event-driven, mutation-heavy, and structurally allergic to the kind of mathematical purity that functional languages demand. You can compile anything to JavaScript — but you can’t compile away the platform’s fundamental nature.

Jane Street’s Bonsai is a monument to that friction. A beautiful, well-funded, world-class monument to the reality that functional purity on the web is a fantasy that requires constant, expensive maintenance.

If you’re a software architect, let this be your wake-up call. The next time someone pitches a pure functional UI framework for the browser, ask them one question:

“What’s your trampoline look like?”

If they don’t know what you’re talking about, they’re selling a dream, not a solution.

And if they do know — well, they’ve already learned the same hard lesson Jane Street learned: the web doesn’t care about your functional purity. It will make you build a bridge out of twigs, and you’ll call it engineering.

FAQ

Q: Is Bonsai actually useful or just a proof of concept?

A: It’s used in production inside Jane Street for their internal web tools. But the need for a trampoline hack shows it’s a pragmatic compromise, not a pure functional ideal.

Q: Does this mean functional programming is bad for the web?

A: Not bad — but it means you’ll pay a tax. The web’s runtime model is imperative. Every functional feature you bring has to be translated or simulated, often with manual workarounds. The more pure you go, the more you fight the platform.

Q: What’s the alternative? Should we just give up on functional principles?

A: No, but be realistic. Use functional patterns where they fit (e.g., Redux, React hooks) without demanding full compositional purity. The browser is a polyglot environment — meet it halfway.

📎 Source: View Source