Bonsai: Janestreet's UI Library (github.com)
258 points by KolmogorovComp 12 hours ago
flufluflufluffy 11 hours ago
> And because Bonsai is written in OCaml, it becomes possible to use the same language and types on both the backend and frontend.
Finally! I was waiting for this to become possible!
kccqzy an hour ago
Why wait? It’s been possible since forever. I wrote UI in OCaml eight years ago. https://github.com/kccqzy/drawing-guessing/blob/master/clien...
deciduously 7 hours ago
There's also Fable for F# but I believe this commenter is being sarcastic. Javascript is a common backend language.
rhgraysonii 5 hours ago
A really great place to reach for this is Elixir/Phoenix now that the set theoretic type system is in place with LiveView. I have been doing some pretty large/complex codebases gradually working towards fully integrating working this way for the past 5 years and it has been great.
philipwhiuk 10 hours ago
Similar attempts include Scalajs.
The general challenge becomes integrating the fractional front-end code written in your backend-language that compiles to JS with the rest of the JS ecosystem.
JaneStreet have a love of writing their own stuff from scratch so it doesn't apply to them but it might to you.
Hence most people end up with frontend-as-backend rather than backend-as-frontend.
vips7L 4 hours ago
KotlinJs and ClojureJs too. You always end up having to write wrappers or dealing with problems that would just work if you just used normal js/ts.
gleenn 2 hours ago
nobleach 8 hours ago
Yup, and Clojure/ClojureScript!
lbourdages 9 hours ago
Couldn't WASM solve that problem once and for all? Is there some limitation that WASM has that JS doesn't?
Disclaimer: I am very inexperienced at front-end development.
danielheath 9 hours ago
applfanboysbgon 7 hours ago
raphinou 9 hours ago
Such attempts are quite common. Some I remember:
https://ocsigen.org/ in Ocaml too
https://websharper.com/ for fsharp and csharp. Really good when I used in in fsharp
Maybe https://melange.re/v7.0.1/ too? (Not sure)
vintermann 8 hours ago
TacticalCoder 7 hours ago
> Finally! I was waiting for this to become possible!
Sarcasm?
Do you want to have a talk as to why JaneStreet wasn't built on JavaScript?
bsmith89 4 hours ago
There's a great Signals and Threads (Jane Street's Podcast) episode about this work: https://signalsandthreads.com/building-a-ui-framework/
strongly-typed 4 hours ago
A framing from that podcast that helped me better understand the role of Bonsai is that it's really a framework for building incremental distributed state machines.
frutiger 3 hours ago
This framing is also in the post. From the readme:
> Bonsai itself -- this library -- is actually more generic than the above makes it sound. It allows you to build general-purpose incremental, composable state machines. Bonsai_web builds on top of that core library, specializing it for interactive browser-based UIs, but we also have Bonsai_term for building interactive terminal-based UIs.
dtornabene 2 hours ago
The docs are a bit sparing but if you read the source its pretty cool to see how they did this.
chrischen 9 hours ago
Curious how this compares to Melange which is used by Ocaml shops as well to double up on Ocaml for both front and backend (ahrefs being the major user and sponsor). Does this mean giving up a lot of the JS ecosystem (React, graphql, etc)?
sroerick 2 hours ago
My understanding is that js_of_ocaml has been around longer and likely has a stronger ecosystem, but Melange was designed more specifically to play nice with the JS ecosystem.
rw2 9 hours ago
I am sure it's very performant, but to me it's extremely ugly; Surely someone can fix margins and still have it be performant.
pgwhalen 8 hours ago
I’m no UI expert - what’s wrong with the margins?
LooseEquipment 8 hours ago
inconsistent and maybe too tight, but I would think those are issues with the sample UIs and not this library
OneDeuxTriSeiGo 7 hours ago
kfse an hour ago
pgwhalen 7 hours ago
troupo 7 hours ago
stronglikedan 3 hours ago
ctxc 8 hours ago
cachius 6 hours ago
What does JaneStreet do besides sponsoring nerdy Youtube channels and writing UI libraries?
markoman 3 hours ago
Jane Street made it's way into today's Wall St Journal for its quantitative prowess and hiring of Math PhD's. What was stunning to hear was that their 2nd quarter profits were a record $10.3 billion, nearly double that of Goldman Sachs and Morgan Stanley (much larger firms).
RugnirViking 6 hours ago
They're a trading firm that hires really clever people to use math to trade. Their strategies are, presumably, very complicated and ever changing, and secrecy about them is the point - you get bigger margins for longer if people don't learn about your 'one weird trick' (that and also that there is presumably another side to your trades losing out on upside, and they might not be best pleased to learn about it.
rudedogg 5 hours ago
> really clever people
Sam Bankman-Fried and his League of Legend rankings would like a word
affyboi 3 hours ago
They’re a market maker
morkalork 6 hours ago
Print money?
andor 5 hours ago
Governments print money, high frequency traders extract money. They would say that they provide liquidity to the market as a service.
morkalork 3 hours ago
user2342 7 hours ago
Interesting! What are Bonsai's dependencies? I use OCaml but - so far - none of Janestreets libraries etc.
LeonidasXIV 7 hours ago
Basically most of Jane Street's published code[0] via its dependency on Core.
[0]: https://github.com/janestreet/bonsai/blob/f31661450eb133fe89...
Schlagbohrer 8 hours ago
Can someone who understands web UI programming tell me if this would be good for my local agent to use to produce HTML based reports and outputs for me? Or for TUI outputs?
tikhonj 5 hours ago
The main thing that Bonsai gets you is a nice programming model for making your UIs interactive. If you're mostly producing static reports (with maybe some basic interactive visualization widgets or something), it will not get you much over generating some variant on HTML + JS.
It makes more sense for applications where you have complex interactive logic in the UI, with a lot of different components that need to control and display some shared state.
derdi 7 hours ago
There was this submission two months ago: https://news.ycombinator.com/item?id=48365904 . Basically they have a TUI frontend for the same thing. And the blog post says: "Bonsai_term would feel familiar to anyone who’d ever done web development here, and it had the huge advantage of being especially amenable to AI assistance. It was actually somewhat of a mystery to us how good the models were at writing Bonsai_term code, given how relatively obscure it is [...]"
antonvs 8 hours ago
Probably not, because your agent won’t have much info about this tool in its training set.
disconcision a few seconds ago
i maintain a codebase that uses Bonzai (https://github.com/hazelgrove/hazel/); agent based development works just fine, though probably a bit more token churn
xvilka 12 hours ago
Looks like it's Web-only, no mention of the native UI support (terminal UI excluded).
avsm 11 hours ago
There's a full terminal implementation of Bonsai as well. I actually use it in my personal workflow these days to manage my contacts database! https://anil.recoil.org/notes/aoah-2025-9
abtinf 5 hours ago
Seconding the sibling comment - what are you using to run your personal site? It is very nice.
aquariusDue 9 hours ago
Unrelated but what do you use to manage your personal website? I love how everything is interconnected.
avsm 5 hours ago
ubercore 9 hours ago
Not sure why, but reminds me of Fog Creek's Wasabi.
hahahaa 11 hours ago
Oh it needs a userland trampoline!
> JSOO does not have tail call optimization
debugnik 5 hours ago
Jsoo supports self-recursive and mutually recursive tail calls, but for general tail calls it would need to trampoline every single call, since the only major browser with proper tail calls is Safari.
adastra22 9 hours ago
The “The thinking in bonsai” link 404s.
This says it is based on Elm. So it has the same clean immutable state structure?
simonask 7 hours ago
I really want to like OCaml. One day I'll get around to learning it.
kubb 11 hours ago
I wish there were more OCaml shops out there
MrBuddyCasino 8 hours ago
This is great. It focuses on utility and information density over design. It looks like someone took a terminal UI and transplanted it to the web, Bloomberg terminal style.
I'm pretty sure you can build tools with this that are fast and pleasant to use.
bobjansen 11 hours ago
This would of been cool back in 2014.
_flux 6 hours ago
Ocsigen and Eliom were started 2005 and are pretty similar, although I can't find any well-known projects using Eliom :/.
Presumably this has learned some lessons from it, so it's probably better.
ramesh31 an hour ago
>"This would of been cool back in 2014."
Pretty much. UI libraries are more or less meaningless now, and I say this as someone who spent the last decade building them. Given a proper data API to work against, you're a single prompt away from a fully tested bespoke lib that's more maintainable and has no dependencies. The weeks of work you saved by reaching for one before is gone, and the tradeoff you had to make of dealing with upstream changes and lack of customization just isn't there anymore.
Traster 11 hours ago
The "Why Bonsai?" I found really funny.
Let me re-write that section for you:
Why Bonsai?
At Jane Street we're super excited by Functional programming and by CAML in particular, so when we need low latency software, we use OCAML, when we need hardware, we write out own langauge - HardCAML, and when we need a Web UI, we build a Web UI framework in CAML. Because we fucking love CAML.
troupo 9 hours ago
And there's nothing wrong with that. Many languages attempt to do the same thing. Why bother with 15 different languages if you can leverage one?
See also LiveView and Hologram for Elixir.
bofeiw 11 hours ago
Agreed, looks like it's reinventing the wheels. Frameworks does not really matter today, AI agents write the code anyway.
KolmogorovComp 11 hours ago
But AI do benefit a lot from a strict compiler, and having a simple language improve a lot on type-safety, so I don't think it is to throw, even today.
rmzs0711 10 hours ago
shAIster 9 hours ago
AI certainly writes Internet comments so that the flock does not have a single minute to get independent thoughts.
ForHackernews 11 hours ago
Better frameworks will still help AIs avoid silly mistakes. A smarter framework means you can be productive with a dumber/cheaper AI.
nbevans 9 hours ago
It looks like a nice little library; but oh boy must this be so limiting for the product teams that are forced to use. Everything looks like it's straight out of the 1990s.
Onavo 4 hours ago
Considering how ridiculously verbose their library is compared to React/Vue it's a good thing we have LLMs to deal with the boilerplate now.
gigatexal 10 hours ago
All your money and retirement funds are safe; I’m too dumb to work at JaneStreet; every time I see OCAML I feel less than and confused.
tecoholic 8 hours ago
Why does this library get posted here, what feels like every month? I remember it seeing at least twice before.
cassepipe 8 hours ago
Been here 5 years, never saw it
jere 8 hours ago
HN is obsessed with anything done in niche programming languages, is my guess.
bmitc 8 hours ago
Also, Jane Street.
yuanBuilds 7 hours ago
It might be a very performant UI framework in OCaml, but all the UI elements look extremely unpolished to me, like what a really smart high-school kid would build the GUI for his side project on Windows in 90s.
Thanks, I can use JS as a functional programming language.
pianoben 22 minutes ago
Windows and especially Macintosh UIs from the late 90s/early 00s were by far the most functional UIs we've ever had since the dawn of the desktop era - user research was a serious discipline, accessibility was baked in to the frameworks, and the HID guidelines that devs adhered to gave us uniform conventions that we users could rely on.
If the biggest criticism of Bonsai is "it ain't pretty but it works", then long life to Bonsai - give me more, please!