r/ocaml • u/codingbliss12 • 2d ago
r/ocaml • u/TomosLeggett • 7d ago
Shout out to Daniel Bünzli
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 • u/crisferojas • 11d ago
A small todo CLI manager migrated to OCaml
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.
r/ocaml • u/Vivid_Pumpkin7290 • 27d ago
Recent grad learning OCaml — how do you actually connect with the community / find OCaml roles?
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 • u/EmergencyNice1989 • 28d ago
OCaml UI framework
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 • u/semgrep-6296 • Jun 02 '26
Pyro Caml: Continuous Profiler for OCaml
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 • u/mister_drgn • Jun 02 '26
Modular explicits in the standard library
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 • u/APOS80 • May 25 '26
Lovely language!
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 • u/Dazzling_Music_2411 • May 19 '26
Ocaml newbie - some trouble with HPLAR
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 • u/I_am_Noro04 • May 16 '26
Who is ocaml for?
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 • u/aryabyte • May 10 '26
codemod CLI in OCaml 5, vendored tree-sitter, Domainslib + Incremental
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 • u/Somtimesitbelikethat • May 04 '26
Feeling a bit of dread over AI
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 • u/chandaliergalaxy • May 01 '26
Largest commercial user of OCaml Jane Street featured in Bloomberg
youtu.ber/ocaml • u/TomosLeggett • Apr 30 '26
OCaml appreciation post
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 • u/DCCXXV • Apr 25 '26
I made a small puzzle game while learning ocaml
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 • u/anon-sourcerer • Apr 25 '26
Learning OCaml by building a habit tracker
youtube.comI’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 • u/Purp1eGh0st • Apr 24 '26
A Path Not Taken for OxCaml
joel.placeI'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 • u/Hot-Weird9982 • Apr 20 '26
Question regarding Jupyter type implementations in VSCode for Ocaml
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?
r/ocaml • u/Beautiful_Exam_8301 • Apr 15 '26
What’s the current state of web dev in OCaml?
I come from a web heavy background, 12 years of js/ts/php, the usual, Laravel, Next, React, etc.
In the past two years I’ve been more interested in statically typed functional languages so I’ve been working with Gleam, developed the Glimr web framework for it. I’ve always been kinda curious about OCaml though, especially after prime made those videos on it a few years ago, are there any rails-like frameworks for it? Or something like jsx to work with html, etc.? Not that I’m looking for that specifically, I’m just wondering what the OCaml community is mainly using for web application development…
r/ocaml • u/Content_Reporter4152 • Apr 10 '26
CocoScript v0.5 - Deep dive into building a native compiler in OCaml
Hey r/ocaml, I posted about CocoScript a while back and wanted to share a detailed update on v0.5. For those who missed it, CocoScript is a compiled language with C/Lua hybrid syntax that targets x86-64 assembly. The entire compiler is written in OCaml.
Architecture Overview
The compiler is structured into clean, composable modules:
Frontend (src/lang/): Hand-written lexer and recursive descent parser generating an AST. Token-based with proper error recovery and position tracking.
Module System (src/modules/): Dependency resolver with circular import detection using topological sorting. Handles #include directives and maintains a module graph.
Optimizer (src/optimize/): AST-level optimization passes including constant folding, dead code elimination, and expression simplification. Works on the IR before codegen.
Backend (src/backend/): Direct x86-64 assembly generation via NASM. Includes a mark-and-sweep GC with type tagging (3-bit tags for int/float/bool/string/array/object/closure/nil).
Error Handling (src/debug/): Rich diagnostics with file/line/column information, similar to Rust's error format.
What's New in v0.5
The garbage collector was a major focus. I implemented mark-and-sweep with proper type tagging - each heap object has a 3-bit tag identifying its type. The GC traces from roots (stack and globals), marks reachable objects, then sweeps and frees unmarked memory. It's triggered on allocation when heap usage exceeds a threshold.
Array utilities now support higher-order functions. map, filter, and sort all accept closures, which required careful handling of captured environments in the codegen phase. Closures are heap-allocated with their environment bundled.
The optimizer got smarter with constant propagation across expressions and better dead code detection. It runs multiple passes until a fixed point.
Module resolution now detects circular dependencies and provides clear error messages about the cycle path.
Technical Challenges
Some interesting problems I solved:
Closure representation: Closures need to capture their lexical environment. I allocate a closure object containing a function pointer and an environment record with captured variables.
GC integration with assembly: Since we're generating raw assembly, I had to manually maintain GC metadata. Every heap allocation updates the allocation pointer and checks the threshold.
Cross-platform calling conventions: Windows uses a different calling convention than Linux (Microsoft x64 vs System V AMD64). The codegen handles both with platform-specific prologues/epilogues.
String interning: Strings are immutable and interned in a global table to avoid duplication and enable O(1) equality checks.
Example Code
Here's a more complex example showing closures and higher-order functions:
#include "io"
func make_multiplier(factor)
return func(x)
return x * factor
end
end
func main()
local times_two = make_multiplier(2)
local times_three = make_multiplier(3)
local numbers = {1, 2, 3, 4, 5}
local doubled = map(numbers, times_two)
local tripled = map(numbers, times_three)
print("Doubled:")
foreach num in doubled do
print(num)
end
print("Tripled:")
foreach num in tripled do
print(num)
end
halt()
end
This compiles to native x86-64 with full closure support and GC.
r/ocaml • u/TheSapphicDoll • Apr 08 '26
what resources to learn ocaml?
Yeah. as per in title. I decided to try to learn OCaml, and while searching for resources..
so far I have stumbled upon..
Learn Programming with Ocaml, and that book seems very promising..
Real World Ocaml. Also seems nice, but... I do not have the experience yet, so if anything, that is for later
Jane Street Ocaml Workshop GitHub repository, that... seems like neat practical way of learning ocaml..
anything more, or any advice would be greatly appreciated!
r/ocaml • u/metaden • Apr 06 '26
Question regarding Dune
I remember a year ago, there was some development around completely standalone opam-less dune build system. Did the tooling development stop? I can't find any recent documentation related to that.
r/ocaml • u/Content_Reporter4152 • Mar 31 '26
CocoScript v0.4 — Major stdlib expansion: file I/O, string utilities, and more (OCaml compiler)
Hey r/ocaml! I've just pushed a major update to CocoScript with a significantly expanded standard library. For those who haven't seen it before, CocoScript is a native compiled language with Lua-style syntax, built entirely in OCaml, that compiles to x86-64 assembly.
What's New in v0.2
This release adds a practical standard library that makes CocoScript actually useful for real scripting tasks:
File I/O Operations:
read_file(path) - Read entire files into strings
write_file(path, content) - Write strings to files
append_file(path, content) - Append to existing files
file_exists(path) - Check file existence
String Utilities:
trim(str) - Remove leading/trailing whitespace
upper(str) / lower(str) - Case conversion
starts_with(str, prefix) / ends_with(str, suffix) - String matching
split(str, delim) - String splitting (basic implementation)
Array Operations:
push(array, value) / pop(array) - Stack operations
Placeholders for map, filter, sort (need closure calling support)
All of these work cross-platform (Windows and Linux) and integrate with the existing type inference system.
Real-World Example
Here's a text processor that demonstrates the new features:
func main()
-- Read and process a file
local content = read_file("input.txt")
if not content then
print("Error reading file")
exit(1)
end
-- Process each line
local lines = split(content, "\n")
local output = ""
for line in lines do
local clean = trim(line)
-- Convert TODO items to uppercase
if starts_with(clean, "TODO") == 1 then
output = output .. upper(clean) .. "\n"
elseif len(clean) > 0 then
output = output .. clean .. "\n"
end
end
-- Save processed output
write_file("output.txt", output)
print("Processing complete!")
end
OCaml Implementation Details
The implementation was surprisingly clean thanks to OCaml's features:
Type Inference Enhancement: I extended the infer_type function to recognize all new builtins, so the print function knows whether to format values as strings or integers:
let rec infer_type cg (expr : Ast.expr) =
match expr with
| Ast.Call ("trim", _) -> TStr
| Ast.Call ("upper", _) -> TStr
| Ast.Call ("lower", _) -> TStr
| Ast.Call ("read_file", _) -> TStr
| Ast.Call ("write_file", _) -> TInt
(* ... *)
Cross-Platform Assembly Generation: Each builtin generates platform-specific assembly. For example, read_file handles both Windows x64 and Linux System V calling conventions:
and builtin_read_file cg args =
match args with
| [path] ->
compile_expr cg path;
if is_linux then begin
asm cg " mov rdi, rax";
asm cg " lea rsi, [rel mode_r]";
asm cg " call fopen"
end else begin
asm cg " mov rcx, rax";
asm cg " lea rdx, [rel mode_r]";
asm cg " sub rsp, 32";
asm cg " call fopen";
asm cg " add rsp, 32"
end;
(* ... error handling and buffer allocation ... *)
Pattern Matching for Clean Code: The builtin dispatch uses OCaml's pattern matching, making it easy to add new functions:
and compile_call cg name args =
if name = "trim" then builtin_trim cg args
else if name = "upper" then builtin_upper cg args
else if name = "read_file" then builtin_read_file cg args
(* ... *)
Technical Challenges Solved
Stack Alignment: Windows x64 requires 16-byte stack alignment before calling C functions. I use this pattern throughout:
asm cg " mov rbx, rsp";
asm cg " and rsp, -16";
asm cg " sub rsp, 32";
asm cg " call strlen";
asm cg " mov rsp, rbx"
Memory Management: String operations allocate new memory using the existing bump allocator. The implementation is simple but effective:
if is_linux then begin
asm cg " mov rdi, size";
asm cg " call _coco_alloc"
end else begin
asm cg " mov rcx, size";
asm cg " sub rsp, 32";
asm cg " call _coco_alloc";
asm cg " add rsp, 32"
end
Type Safety: The type inference system ensures that string functions return TStr and comparison functions return TInt, so the print builtin can format values correctly without runtime type tags.
Compiler Architecture
For those interested in the overall structure:
Lexer (
) - Hand-written, handles keywords, operators, string escapes
Parser (
) - Recursive descent with proper operator precedence
AST (
) - Clean algebraic types for expressions and statements
Codegen (
) - Direct AST → x86-64 assembly (no IR)
GC (
) - Bump allocator with 1MB arenas
The entire compiler is about 3,000 lines of OCaml, with ~1,600 lines in codegen alone.
Why OCaml Was Perfect for This
Pattern matching made AST traversal and code generation incredibly clean
Algebraic types for expressions and statements are exactly what you need for a compiler
Type safety caught countless bugs during development
Immutability by default made reasoning about compiler state easier
Performance - compilation is fast, even with no optimization passes yet
What's Next
I'm working on:
Module system - Tokens for import/from/as are already in the lexer
Better error messages - Infrastructure exists, needs parser integration
Mark-and-sweep GC - Currently using bump allocator (leaks memory on string concat)
Optimization passes - Constant folding, dead code elimination
Self-hosting - Rewrite the compiler in CocoScript itself
Try It Out
GitHub: https://github.com/dwenginw-tech/cocoscriptomal
The project is MIT licensed. The compiler requires OCaml 5.4.1, opam, dune, NASM, and GCC. End users only need the compiled binary, NASM, and GCC (bundled in the Windows installer).
Installation on Linux:
curl -o- https://raw.githubusercontent.com/dwenginw-tech/cocoscriptomal/main/install.sh | bash
Documentation
I've added comprehensive documentation with this release:
STDLIB_REFERENCE.md - Complete API reference with examples
CHANGELOG.md - Version history and feature tracking
IMPLEMENTATION_SUMMARY.md - Technical implementation details
Feedback Welcome
I'd love feedback on:
The compiler architecture and OCaml code organization
Language design decisions (Lua syntax vs alternatives)
Standard library API design
Performance optimization opportunities
Ideas for the module system
Thanks for reading! Happy to answer questions about the implementation or design choices.