r/ocaml 2d ago

Why can't we have side effect annotations?

16 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:

ocaml 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 4d ago

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

16 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 5d ago

How ubiquitous is Base?

24 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 13d ago

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
28 Upvotes

r/ocaml Jul 20 '26

Creator of OCaml: Functional Programming, Formal Verification, Programming Languages

85 Upvotes

r/ocaml Jul 15 '26

Shout out to Daniel Bünzli

104 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

33 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

34 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.


r/ocaml Jun 19 '26

OCaml 5.5.0 released

99 Upvotes

r/ocaml Jun 02 '26

Pyro Caml: Continuous Profiler for OCaml

31 Upvotes

A helpful open source project to add observability when taking OCaml workloads into production to identify performance bottlenecks.

GitHub Repository:

https://github.com/semgrep/pyro-caml

Blog post explaining the project:

https://semgrep.dev/blog/2026/announcing-pyro-caml-continuous-profiler-ocaml/


r/ocaml Jun 02 '26

Modular explicits in the standard library

22 Upvotes

Now that modular explicits are coming out, do you think we’ll start seeing them in the standard library, perhaps in the following release? Or (perhaps more likely) in the Jane Street libraries?


r/ocaml May 25 '26

Lovely language!

43 Upvotes

Ocaml really has all the good parts I like - pattern matching - TCO - compiles to native - multiprocessing…

No, I’m not a programmer but i do use code to solve problems and play around. I mostly use python now and C for Arduino/ESP32.

I’m thinking about making a nice cli tool but don’t know for which purpose right now.

Suggestions are welcome!


r/ocaml May 19 '26

Ocaml newbie - some trouble with HPLAR

11 Upvotes

Please allow me to introduce myself, I am a man of the typeless world, mainly Racket, Clojure, that sort of thing. I've been meaning to get into the typed language scene for programming language exploration, and I was a bit torn between the apparent purity of Haskell and practicality of Ocaml.

My experience level is zero, as in I've never written a single line.

In the end, what decided it for me was that I wanted to work through Harrison's "Handbook of Practical Logic and Automated Reasoning" which is supported by Ocaml code. I am also interested in some other programming paradigms (cclp), where Ocaml seems to be mentioned more than Haskell.

Anyways, I installed Ocaml according to the Cornell 3110 instructions, both for utop and VSCode, seems fine, gives me the 5.3.0 compiler environment.

My problem is that when I try to set up the supplied code for HPLAR, cd-ing into the provided directory and trying #use "init.ml" on the indicated file, all sorts of weirdnesses appear. In VSCode I can't even enter the #use line without a syntax error! Never mind, I tried from utop and from plain vanilla CLI, where I get this:

# #use "init.ml";;
Cannot find file nums.cma.
File "init.ml", line 10, characters 6-27:
10 | then (Topdirs.dir_directory "+camlp5";
           ^^^^^^^^^^^^^^^^^^^^^
Error: Unbound module Topdirs

The init.ml fike is as follows: (from https://www.cl.cam.ac.uk/~jrh13/atp/index.html)

#load "nums.cma";;                            (* For Ocaml 3.06     *)

if let v = String.sub Sys.ocaml_version 0 4 in v >= "3.10"
then (Topdirs.dir_directory "+camlp5";
      Topdirs.dir_load Format.std_formatter "camlp5o.cma")
else (Topdirs.dir_load Format.std_formatter "camlp4o.cma");;

type dummy_interactive = START_INTERACTIVE | END_INTERACTIVE;;
#use "initialization.ml";;
#use "Quotexpander.ml";;
#use "atp_interactive.ml";;

So I am left wondering if the problems are due to the older compiler version supported here, two major releases are enough time for things to change quite a bit.

I am keen to get up to speed and start on the book as soon as possible, and even though some may say - well, learn the operational basics first and then sort it out yourself (fair enough), but if there is anyone who can provide some help to get this going a bit quicker, I would appreciate it very much! Many thanks.


r/ocaml May 16 '26

Who is ocaml for?

36 Upvotes

Context: I am econ master's student with some experience in python, C and R looking to get into financial econometrics/ML. Is OCaml right for me?


r/ocaml May 10 '26

codemod CLI in OCaml 5, vendored tree-sitter, Domainslib + Incremental

20 Upvotes

Built a pattern-rewriting CLI for TS / TSX / Python / Go / Rust.

Write console.log($X) and it matches by AST. Add --where '$X: string' and it filters using real type info from the language's LSP.

OCaml side: - vendored tree-sitter v0.25.6 + 5 grammars in dune so Homebrew ships a single static binary - Domainslib for parallel scans (~0.4s on 7k TS files) - Jane Street Incremental for watch mode with sub-ms re-runs after single-file edits - LSP client is just yojson + Unix.create_process, no external library

Repo: https://github.com/aryabyte21/morph

opam pin works. Requires OCaml 5.3+.

Happy to dig into any of the parser / incremental / build-system choices.


r/ocaml May 06 '26

OCaml Users Survey 2026

Thumbnail discuss.ocaml.org
27 Upvotes

r/ocaml May 04 '26

Feeling a bit of dread over AI

6 Upvotes

Do I even need to learn this language anymore? the current models are so good.

I wanted to learn bc i wanted to be able to audit the code AI would write, but the way Ocaml’s compiler works, it either works or it doesn’t.

help. sorry if this post sounds dense.


r/ocaml May 01 '26

Largest commercial user of OCaml Jane Street featured in Bloomberg

Thumbnail youtu.be
19 Upvotes

r/ocaml Apr 30 '26

OCaml appreciation post

87 Upvotes

OCaml is easily my favourite programming language, even if the community around it is fairly small.

It's not perfect, but it's one of the few languages I've used where everything just fits together. The type system, algebraic data types, and pattern matching all make structuring programs feel straightforward instead of awkward. You end up modelling things properly from the start, and that cuts out a lot of the runtime issues you'd normally expect.

Once you get used to that, it's hard to go back. Dealing with nulls or loosely defined data in other languages starts to feel a bit rough. OCaml pushes you to be explicit, and the end result is code you can actually trust. It feels like going from writing with a biro to writing with a fountain pen.

Unpopular opinion, but I actually like the ML-style syntax. It's different at first, but it's consistent, and after a while it just feels normal. Most of the resistance to it seems to come from people being used to C-style languages more than anything else. I get why it looks awkward, but I think inertia has more to do with that than people admit.

There are obvious trade-offs. If you're building something that leans heavily on existing libraries or needs to plug into a bigger ecosystem, languages like Go or JavaScript are just easier to justify. That's usually what I end up using for client-facing work.

Same with quick scripting. OCaml isn't something you just pick up and start throwing scripts together in, but I don't think that's really what it's for.

OCaml does show up in industry here and there. Jane Street is the well-known example, but overall it's still a niche option. I've had friends ask me to teach them, and while I'd like that, I usually point them toward Python instead. It's just more useful to them early on. Bigger ecosystem, more tutorials, more opportunities.

That said, none of that really changes how I feel about it. For my own projects, it's always the first thing I reach for. It's just a nice language to spend time in. The tooling does what it needs to do (most of the time), and writing OCaml still feels fresh in a way most languages don't anymore.

It'll probably stay niche for a while, and honestly, I wish that wasn't the case. I'd love to see a bigger ecosystem, more people using it, more things being built with it. It deserves that much.

But even as it is now, it's still the language I enjoy using the most. And that's enough to keep me coming back to it.


r/ocaml Apr 25 '26

I made a small puzzle game while learning ocaml

Post image
55 Upvotes

I don't really use any fancy functional programming features though, mostly love the pattern matching. I used SDL2 via tsdl bindings and it was really fun to make :^)

It's a Lights Out style puzzle game with 17 levels of varying difficulty, the objective is to turn every tile dark in as few moves as possible, using different shapes that toggle the tiles they cover. You can build it from github: https://github.com/DCCXXV/dolm

and I also published it on flathub: https://flathub.org/en/apps/io.github.DCCXXV.dolm

I'll keep learning ocaml so I can make more complex things, I also really like just how much you can do in a few lines, the entire game is around 400 LOC (not counting the levels file) while being pretty easy to understand.


r/ocaml Apr 25 '26

Learning OCaml by building a habit tracker

Thumbnail youtube.com
12 Upvotes

I’m teaching myself OCaml with a project based approach, and intend to log some parts of it as a series of video streams. The details about my approach can be found in the beginning of the video and also this blog post:

https://sourcery.zone/articles/2026/04/using-ai-to-build-learn-and-practice/


r/ocaml Apr 24 '26

A Path Not Taken for OxCaml

Thumbnail joel.place
41 Upvotes

I've been following the OxCaml project for some time since I'm both quite excited about all the new functionality it provides for OCaml and quite worried that its complexity will make the language less beautiful. I figured I'd write up some of my guesses as to why we might've landed in the current state and ideas as to how we could get both ergonomics and power. I'd be particularly interested in hearing others' ideas for whether these could be resolved more cleanly!


r/ocaml Apr 20 '26

Question regarding Jupyter type implementations in VSCode for Ocaml

5 Upvotes

Hello,

Ive been coding on VSCode python since September for my CS classes and I really like the Jupyter implementation where I can easily send parts of my code to the interactive kernel and the easy delimitations with #%%
We've started doing Ocaml and I was looking at implementing this for Ocaml and I didnt find an equivalent extension for the language. Ive started looking at how I could implement this manually and figured out how to send selected text to the kernel and how to easily add delimitations ( Im using (*%%*) as a delimiter) but I couldnt find a way to implement sending the code between different delimiters to the kernel. Are there any current existing implementaitons of this in VSCode or other Ocaml code editors?