r/solidjs • • 13d ago

Solid apps in OCaml

Post image

Hi r/solidjs!

At Hypha we build software in OCaml, with an open stack of our own. The backend part is covered by Spindle, our fantastic web framework, so nothing to complain about there. The frontend is a different beast, though.

What would be really great is to build full-stack reactive apps in OCaml on Solid, from one coherent set of libraries, for ourselves and for our customers, so that backend and frontend share one great language, one toolset, and the same high bar.

Unfortunately for us, Solid never had complete OCaml bindings, so after some investigation I made our own, for Solid itself and for Kobalte. And for the sake of having one of the best UI kits around, I also ported HeroUI, nearly in full, from React and React Aria onto Solid and Kobalte. Then came charts (rhp) and Gravity UI's icons. Sorted.

Even if you've never tried OCaml, you should be able to read the code, as it's pretty close to JSX/TSX markup:

module S = Solidtype.Solid
module Jsx = Solidtype.Jsx

let%component make ~(label : string) () =
  let count, set_count = S.create_signal 0 in
  <button on_click=(fun _ -> S.update set_count (fun c -> c + 1))>
    (fun () -> Jsx.string (label ())) ": " (fun () -> Jsx.int (S.get count))
  </button>

Why OCaml? Glad you asked. Agents now write much of our code, and a model guesses wherever nothing tells it otherwise. OCaml's types leave it much less room to guess, and the compiler is fast enough to answer inside an agent's loop. It's also nice to have one language for the whole stack, as TypeScript or Clojure gives you, and OCaml does too.

The docs have plenty of live examples and everything you or your agents need to build modern web apps in OCaml and Solid.

👉 https://hyphatech.github.io/solidtype/

53 Upvotes

5 comments sorted by

3

u/yangshunz 13d ago

ReasonML v2?

1

u/rzaiev 13d ago

Not really. Reason was a JS-like syntax for OCaml. This is plain OCaml with JSX (mlx to be precise) as syntax sugar, compiled with Melange, plus bindings for Solid, Kobalte, HeroUI and more. The goal is one language and toolset with shared code for the whole stack.

2

u/Lithaldoryn 5d ago

Hey hey 👋 This is just an awesome idea and I truly thank you all for the time spent on this.

I've never tried OCaml but this is tempting for a side project and could be a good opportunity for jumping into the rabbit hole.

Makes me also want to try doing this kind of things for Elixir which is my language of choice usually.

5

u/Master-Guidance-2409 13d ago

this syntax makes me want to kill myself, jesus no wonder nobody uses this shit.

1

u/TechZazen 9d ago

In the words immortalized for all time: “Yes, well, that's the sort of blinkered, philistine pig ignorance I've come to expect from you non-creative garbage. You sit there on your loathsome, spotty behinds squeezing blackheads, not caring a tinker's cuss for the struggling artist. You excrement!”

Come on, OCaml is heavily concentrated in high-frequency trading (HFT), formal verification, compilers/static analysis, and blockchain/protocol engineering. Very high rates for something that only a few select developers use. Just saying…