r/ocaml • • 2d ago

Looking For Criticism on My First OCaml Project

20 Upvotes

Hello everyone, I've been meaning to get into functional programming for some time now. I made multiple attempts to learn Haskell alas all of them ended in vain. A couple days ago, I decided to give OCaml a shot, and learn it through doing a project, because there i no better teacher than just wandering around and finding out.

So, I have this other project of mine which uses a specific syntax in markdown in the project source tree to keep track of the issues. I wanted to have some sort of a simple website for it so I decided to write a simple static site generator for that particular markdown subset in OCaml.

The project source is here, I'm looking forward to see where I made mistakes functional-style-wise as an all-time C-style imperative programmer.

Thanks!


r/ocaml • • 2d ago

ML Modules for Mere Mortals

Thumbnail thunderseethe.dev
35 Upvotes

r/ocaml • • 4d ago

solidtype: SolidJS for modern OCaml

Post image
51 Upvotes

Hi r/ocaml!

Not so long ago I introduced Spindle, our Eio-native web framework for OCaml 5. Since then it has gained MCP servers and clients, OAuth, access policies, and a lot of stabilizing improvements on our road to 1.0.

But the backend is only half of the story. What we really want is to build full-stack apps in OCaml from one coherent set of components, for ourselves and for our customers.

That's what solidtype is, in a nutshell:

  • Complete bindings to Solid 1.9: the reactive core, stores, the web renderer, server rendering and hydration

  • Complete bindings to Kobalte: every accessible component, generated from Kobalte's own type declarations and tested against TSX reference implementation

  • A (nearly) complete port of HeroUI's design system on top of Kobalte

  • Charts and Gravity UI's icons because we can

How it works. I carefully studied the path of solid-ml, now discontinued, to avoid the same trap. Instead of reimplementing Solid's compiler in OCaml, solidtype keeps Solid's own. The browser gets exactly the code Solid emits for TSX, and Solid's libraries run unchanged behind typed bindings.

To make that possible, we built a processing pipeline:

  1. mlx parses OCaml's JSX

  2. ppx_solidtype lowers each element to typed marker calls. Attributes are checked against types generated from Solid's

  3. Melange compiles the result to JavaScript

  4. vite-plugin-solidtype turns the markers back into Solid-ready JSX

  5. Solid's own compiler compiles that JSX, exactly as it compiles TSX

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

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


r/ocaml • • 4d ago

Qwen3.8-Flash-Next is really good at OCaml coding.

20 Upvotes

I'm running Qwen3.8-Flash-Next (QFN) locally on my Strix Halo box and I've got it creating a C to microcode compiler for a specialized processor architecture. It's doing really surprisingly well. We'd created this in C around the beginning of the year. I recently got QFN running well locally so I figured I'd give it a challenge and have it code it in OCaml. But the architecture is way better than the C implementation and now I'm thinking we should probably replace our C implementation with this.


r/ocaml • • 16d ago

Offering: 1-on-1 OCaml / Functional Programming tutoring

Thumbnail reddit.com
0 Upvotes

Hey Folks , just a quick update on my availability. I currently have only 4 slots left!

Eastern Time (ET)

• Morning Slot: 9:30 PM – 1:30 AM ET (Late night)

• Evening Slot: 8:30 AM – 12:30 PM ET (Morning)

Pacific Time (PT)

• Morning Slot: 6:30 PM – 10:30 PM PT (Evening)

• Evening Slot: 5:30 AM – 9:35 AM PT (Early morning)

Drop a comment or send a PM if you want to grab one of the remaining 4 slots!


r/ocaml • • 26d ago

Spindle: an Eio-native web framework for OCaml 5

Post image
69 Upvotes

Hi r/ocaml!

I'd like to introduce Spindle, the web framework we've built in-house for our clients' backends. It's one of the core components of the Hypha Stack ecosystem, but can be used on its own.

  • RFC-strict and ergonomic, on its own HTTP/1.1 engine

  • Eio-native: straight-line handlers, multicore by design

  • Typed end to end: JSON derived from your types, every input validated

  • Interactive OpenAPI docs via Scalar at /docs, generated from your routes

  • Front end in sync: Zod or Melange schemas derived from your OCaml types

  • Batteries included: Postgres, WebSockets, SSE, sessions, logging, traces and metrics

👉 Docs: https://hyphatech.github.io/spindle/


r/ocaml • • Oct 16 '26

Offering: 1-on-1 OCaml / Functional Programming tutoring

Thumbnail reddit.com
1 Upvotes

r/ocaml • • Oct 14 '26

Guys i do not want to learn Haskell anymore now it's ocaml

Thumbnail reddit.com
0 Upvotes

r/ocaml • • Oct 11 '26

Ocaml or haskell?

Thumbnail reddit.com
17 Upvotes

r/ocaml • • Oct 10 '26

unikernels were hard. key word: were.

Thumbnail
ghuntley.com
42 Upvotes

r/ocaml • • Oct 03 '26

Offering: 1-on-1 OCaml / Functional Programming tutoring

27 Upvotes

Offering: 1-on-1 OCaml / Functional Programming tutoring

Hi everyone!

I'm a recent graduate who has been focusing heavily on OCaml and functional programming, and I've recently started tutoring OCaml as well.

I'm currently teaching a student taking Penn CIS 1200, and I've really enjoyed helping beginners understand functional programming rather than simply giving them solutions.

My approach is:

Concept → simple explanation → example → student attempts it → code in utop → debug → explain it back

I can help with:

  • OCaml fundamentals

  • Pattern matching

  • Recursion

  • Higher-order functions

  • Currying & partial application

  • Lists and trees

  • Modules and abstraction

  • Functional programming concepts

  • Debugging

  • Exam preparation

I'm especially interested in working with people who are completely new to OCaml.

I teach remotely over Zoom and currently have a couple of openings for 1-on-1 sessions.

If you're learning OCaml and think 1-on-1 guidance would help, feel free to DM me with what you're currently working on. We can discuss the session format and rate from there.


r/ocaml • • Sep 21 '26

I've just created a GC runtime for my OCaml (subset) to LLVM IR compiler! 🦝

Post image
32 Upvotes

Before anyone call it out: Yes, with the lack of features, it's technically not an "OCaml" compiler as of now. It's more akin to a simple ML language 😅 But I only realized that after posting my project to this subreddit and someone comment about it 😂 So it's kind of "too late" for me to rename this project, and the OCaml language reference was my reference since the start 😊

As for the GC, since it does not support mutation yet, the GC does not need to track inter-generational pointers!

However, despite the many lacking features, no pointer tag bit, use of compile-time monomorphization, and use of LLVM optimization passes, it still fails to perform better than `ocamlopt` in the general case 😂 You can check out the benchmark section in README.md.

I've tried many things, profiling with `perf`, fine tuning GC parameters, but it still fails to be faster 🥲

One thing I constantly see in `perf` reports even before introducing the GC runtime is the comparitively high system time vs user time and high percentage of branch misprediction 🤔

I originally suspect it was because I haven't implemented the GC -> more memory usage -> more page faults. But now that I've implemented the GC, it's still not performing that well.

One other thing that caught my attention was it turns out OCaml stack is managed similarly to heap? CMIIW. Maybe that gave OCaml a significant advantage?


r/ocaml • • Sep 16 '26

Simple and Efficient Row-Level Security

Thumbnail acadia.engineering
25 Upvotes

OCaml was how I learned typed FP, and it was an important influence on how I designed Elm and Acadia. This post is about one of my favorite aspects of the Acadia compiler, symbolic evaluation, and I thought you might find it interesting.

The compiler evaluates queries as much as possible at compile-time, so it is able to reduce case expressions, let expressions, etc. One neat outcome of this is that large expressions can sometimes be fully evaluated at compile-time, so they end up having no runtime cost at all!

I like this feature because it also only works because the query language is not Turing Complete. The design choices described here that avoids 1+N patterns, also guarantees that queries terminate. This means they terminate whether you run them at runtime or at compile-time!

Anyway, I am generally curious how this sort of thing might fit with the OCaml programs people are writing these days. I have a draft of the --gen-ocaml flag to get binary encoders/decoders that connect Acadia and OCaml, but I'm not tapped in enough to OCaml world to know how this sort of thing would fit into the modern OCaml ecosystem.


r/ocaml • • Sep 10 '26

Help me find the problem in this

Post image
0 Upvotes

I’ve recently entered college and we started coding in Ocaml. This code corresponds to an exercise that asked for the following code:

Test if a 3 digit number is a perfect square and test if the two greater digits of this number added together also make a perfect square. If all conditions are met, give “true”, else “false”. If the number isn’t 3 digits, give an error code.

Here’s my problem: the code works and gives a bool result, but it only gives “false” even if the number should work (ex: 100, 400, they both give “false”.)

I’m out of ideas and can’t figure out why I only get “false” results. Please help me out!

and please don’t comment on the eyesore, I know it’s painful to see


r/ocaml • • Sep 03 '26

BOB 2027 (Berlin, Feb 26) - Call is open!

18 Upvotes

This year peaked with lots of OCaml content, we'd be happy to have more of that!
bobkonf.de/2027/cfc.html


r/ocaml • • Aug 26 '26

Why can't we have side effect annotations?

18 Upvotes

One of the things I like about OCaml is that it doesn't force you to write purely functional code. You can mutate values, throw exceptions, perform I/O, and generally use imperative features when they're appropriate.

I also like that OCaml is fairly explicit about this. If you're passing a reference around or mutating a value, it's usually apparent from the code.

One thing I don't particularly like, though, is that there's no indication in a function's type of whether it performs side effects. There's no equivalent of a ! suffix or an effect annotation, so you can call a function without knowing that it might throw an exception, mutate some state, perform I/O, etc.

The only real way to find this out is to inspect the implementation or rely on the documentation, assuming the author has actually documented it.

I'm wondering whether this is primarily a technical limitation or simply a design decision by the OCaml team. What prevents the compiler from analysing a function's body and determining that it uses things such as raise, :=, ref, I/O operations, and other effectful constructs, then incorporating that information into its type? For example:

val foo : unit -> int ![IO, State]

Obviously, there are complications around higher-order functions, modules, abstractions, user-defined effects, and so on, but could some form of effect inference make it possible to distinguish pure functions from effectful ones?

I'd be interested to know whether this has been considered for OCaml, and whether there are fundamental reasons why it doesn't work well, or whether it's simply a deliberate trade-off in the language's design.


r/ocaml • • Aug 24 '26

Production Web Servers/Frameworks that support EIO(OCaml 5.5+)

19 Upvotes

Hello all,

Are there any production-quality web servers(and/or frameworks) that support EIO(not LWT) and compatible with current OCamll(5.5?)


r/ocaml • • Aug 23 '26

How ubiquitous is Base?

25 Upvotes

I've recently started to learn OCmal, and while the docs are quite clear, I am trying to gain an understanding of the community best practices.

When looking at packages, I've found many of them using Base and Collections.

Should I be using them "as a default" for any decent size project?

I was also surprised to find a janestreet format baked into ocamlformat. Are they such a big part of the ecosystem? It seems many projects use both their Base package and their formatting.

What are some other "canonical" packages I should know?


r/ocaml • • Aug 15 '26

CocoScript v0.6.0 — native Win32 GUI (real windows + text), compiled to x86-64 assembly

14 Upvotes

Just shipped CocoScript v0.6.0. For anyone new: it's a native compiled language with Lua-style syntax, written entirely in OCaml, compiling to x86-64 assembly via NASM — with a mark-sweep GC, a module system, and an optimizer.

New in v0.6.0 — a native Win32 GUI, with the whole Win32 runtime emitted as x86-64 assembly (no C glue, no external GUI library). Add #include "gui" and the compiler auto-links user32/gdi32:

- Windows: gui_window / gui_show / gui_loop

- Text: gui_text(hdc, str, x, y), gui_color(hdc, r, g, b)

- Callbacks: gui_on_paint / gui_on_click / gui_on_key (named functions and lambdas)

- A self-contained Windows installer bundling the whole toolchain (nasm + gcc/ld/as) — no MSYS2 needed on the user's machine

The fun part was debugging why the window was invisible: the WndProc wasn't forwarding lParam to DefWindowProcA, so WM_NCCREATE failed and CreateWindowEx returned NULL.

Release + installer: https://codeberg.org/cocoscriptomal/cocoscriptomal

Feedback welcome!


r/ocaml • • Jul 27 '26

Challenging Claude's creativity with IFS fractals and OCaml

Thumbnail
cedricbonhomme.org
30 Upvotes

r/ocaml • • Jul 15 '26

Shout out to Daniel Bünzli

105 Upvotes

Just wanna give a quick hats off to Daniel Bünzli for all his work with OCaml. He seems to have created a lot of really well designed, comprehensive libraries, tools and utilities for the OCaml community.

He's made a whole declarative vector graphics library, a fairly well polished Js_of_ocaml middleman, a unicode decoder, a slightly nicer alternative to TyXML, an API for interfacing with the QOI image compressor...the list goes on.

Just take a look at his stuff: https://erratique.ch/software

FYI: I am not associated or affiliated with this man in any way, I am just impressed and wanted to send some appreciation


r/ocaml • • Jul 11 '26

A small todo CLI manager migrated to OCaml

35 Upvotes

Inspired by Steve Losh's original t. I originally built this in Swift to manage my work tasks from the terminal and commit directly from a project's todo list. I recently rewrote it in OCaml while learning functional programming, and ended up falling in love with the language along the way. Sharing it in case it's useful to anyone.

https://github.com/crisfeim/t


r/ocaml • • Jun 25 '26

Recent grad learning OCaml — how do you actually connect with the community / find OCaml roles?

36 Upvotes

Hey all, recent CS/AI grad here. Got into OCaml a few weeks ago and ended up more hooked than I expected landed two small merged PRs into the stdlib (fixed some doc bugs) and I'm now poking around ocaml.org issues for something bigger.

I'm documenting the journey on LinkedIn/X as I go, but I want to actually plug into the community properly, not just post into the void. A few things I'm trying to figure out:

- Where do OCaml people actually hang out beyond this sub Discord, Discuss, IRC, conferences?

- For someone without prior FP/OCaml experience, what made the difference between "learning the syntax" and getting taken seriously as a contributor?

- Realistically, how do OCaml roles surface job boards, referrals, OSS work turning into offers, something else?

Not looking for a shortcut, just don't want to be doing the wrong things for months without knowing it. Any pointers (or even "here's what worked for me") appreciated.


r/ocaml • • Jun 24 '26

OCaml UI framework

35 Upvotes

I am working on an F# Avalonia application for text editing, Markdown viewing, and DataGrid display. It uses a lot of async tasks, database access (SQLite or PostgreSQL) through ADO.NET, and manipulates a large amount of Unicode text.

So far, I am happy with my technology choices, but I was wondering whether it would be possible to build the same kind of application in OCaml. Bogue seems like an interesting GUI framework, but it does not appear to be at the same level of maturity as Avalonia, and it does not support mobile platforms.

Do you think migrating to OCaml would be realistic, or is OCaml not particularly well suited to these requirements? My needs are fairly modest, but I would be interested in hearing from people who have experience building desktop applications in OCaml.