OCaml

@ocaml.org

https://ocaml.org

Dune 3.24.0

The Dune team is pleased to announce the release of dune 3.24.0. Highlights include the following * Dune package management now uses the relocatable compiler by default, for all supported compiler versions. This brings a massive speedup to workspace setup in the many cases where built compiler versions can be reused. (ocaml/dune#14357, @Alizter) * Directory targets are now generally available (ocaml/dune#14579), allowing tools to produce entire directory trees as targets. See the documentation on directory targets for details. * Path handling has been refined, improving the consistency of paths across platforms (ocaml/dune#14278 and ocaml/dune#14278) and using a more consistent and disciplined location for %{bin:NAME} variable expansions (ocaml/dune#14432). * Path-valued percent forms (%{bin:...}, %{dep:...}, %{path:...}, and friends) now expand same-directory paths with a leading ./, so that shells like bash in (bash ...) and (system ...) actions execute them directly instead of looking them up in PATH (ocaml/dune#15156). This is a breaking change for configurations that were handling paths naively, and neglected to normalize the representation before using it test fixtures or for constructing other strings. * The deprecated lang coq has been removed, as scheduled, superseded by lang rocq. See ocaml/dune#12788 for details. See the full changelog for all new features and fixes, and for attribution to the contributors who made it all possible. Thank you, contributors! If you encounter a problem with this release, please report it in our issue tracker.

dlvr.it

Release of OCaml 5.5.0

We have the pleasure of celebrating the birthday of Blaise Pascal by announcing the release of OCaml version 5.5.0. Release Highlights Some of the highlights of OCaml 5.5.0 are: Module-dependent Functions Modules can now be used as function arguments in a form of lightweight functors. For instance, we can define a function for printing a map generated by the Map.Make functor: let pp_map (module M: Map.S) pp_key pp_v ppf set = if M.is_empty set then Format.fprintf ppf "ø" else let pp_sep ppf () = Format.fprintf ppf ",@ " in let pp_binding ppf (k,v) = Format.fprintf ppf "@[%a@ =@ %a@]" pp_key k pp_v v in Format.fprintf ppf "@[{@ %a@ }@]" (Format.pp_print_seq ~pp_sep pp_binding) (M.to_seq set) We can then apply this function on a string map module String_map = Map.Make(String) with let () = let m = String_map.of_list ["Zero", "Zero"; "One", "Un"] in let pp_str = Format.pp_print_string in Format.printf "%a@." (pp_map (module String_map) pp_str pp_str) m Compared to first-class modules, the type of the function pp_map type 'a printer = Format.formatter -> 'a -> unit val pp_map: (module M: Map.S) -> M.key printer -> 'a printer -> 'a M.t printer is dependent over the value of the module S, and thus the function can only applied over a statically known module: let f (): (module Map.S) = if Random.bool () then (module Map.Make(Int)) else (module Map.Make(Float)) let fail = pp_map (f ()) Error: This expression has type (module M : Map.S) -> (Format.formatter -> M.key -> unit) -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a M.t -> unit but an expression was expected of type (module Map.S) -> 'b The module M would escape its scope This function is module-dependent. The dependency is preserved when the function is passed a static module argument (module M : S) or (module M). Its argument here is not static, so the type-checker tried instead to change the function type to be non-dependent. Relocatable Compiler A compiler installation can now be moved or copied with no risk of hard-to-debug errors due to mixing incompatible bytecode runtime interpreters. In practice, this means that creating a local switch when there is a global switch with the same compiler version and configuration available can be done by cloning the global switch rather than recompiling the whole compiler. This should considerably reduce the time required to create new local opam switches out-of-the-box. Polymorphic Functions as Function Arguments Higher-rank polymorphic functions can now be defined directly by using an explicit type annotation in a function argument let apply_map (map: 'a 'b. ('a -> 'b) -> 'a list -> 'b list) = map string_of_int [1;2;3], map List.singleton ["x"; "y"] let _ = apply_map List.map Previously defining such a function required going through either a record or an object with a polymorphic field or methods type map = { map: 'a 'b. ('a -> 'b) -> 'a list -> 'b list } let apply_map {map} = map string_of_int [1;2;3], map List.singleton ["x"; "y"] Search and Replace Substring Functions The String module has been extended with many functions for searching and replacing substrings inside a string. let _true = String.includes ~affix:"aba" "abbaba" let sentence = String.replace_all ~sub:"𝄽" ~by:"word" "A 𝄽 is re𝄽ed" The substring search is using the 2-way string matching algorithm which has the advantage of requiring constant space memory overhead independently of the needle size. Generalised Local Definitions It is now always possible to define locally a type, a class, a module type or any kind of item that can be defined globally: let mandelbrot n x = let type t = Converge | Escape of int in ... match orbit n x with | Converge -> 0 | Exit_at n -> colorize n External Types When interfacing with foreign function libraries, it is now possible to define external type type int_gmp = external "mpz_t" type float_gmp = external "mpf_t" Compared to an abstract type definition, the external type name "mpz_t" (resp. mpf_t) makes the type distinguishable from any non-abstract types or external types with a different name. In particular, this makes FFI types better behaved when combined with Generalised Abstract Data Types (GADTs). For instance, The typechecker is able to prove that let ok: (int_gmp,[` A] ) Type.eq -> _ = function _ -> . is a total function because the external type int_gmp is not compatible with a polymorphic variant type. Warning: Abstract types in the current module The astute reader has probably noticed in the definition above that, in OCaml 5.4.0, the typechecker does accept type int_gmp let ok: (int_gmp, [` A] ) Type.eq -> _ = function _ -> . as total. Indeed until OCaml 5.5.0, abstract types defined in the current module type a type b were considered as unique and provably different let f: 'x. (a,b) Type.eq -> 'x = function _ -> . However, this special rule for local definition of abstract types was very brittle. As soon as one moved outside of the current module, it was no longer possible to prove that the types were different. module M = struct type a type b end let fail: 'x. (M.a,M.b) Type.eq -> 'x = function _ -> . Error: This match case could not be refuted. Here is an example of a value that would reach it: Equal This special typechecking rule has been removed in OCaml 5.5.0. If you were relying on it, for instance, because you used an abstract type as type-level label in a GADTs, you can change your abstract type definition to a possibly private abbreviation of a polymorphic variant type a = private [`A] type b = [`B] or a (possibly private) sum type type a = A type b = private B If you were using an abstract type as both a type-level label and a FFI type, you can now use an external type definition which will give you a provably distinct type even outside of the current module. GC improvements Some of the ongoing work to improve the pacing of the garbage collector has been integrated in OCaml 5.5.0, two of the important changes in OCaml 5.5 GC are * the addition of a sweep-only phase at the start of major GC * the addition of an idle phase to smooth the behaviour of the GC at the start. Many incremental changes * The Windows implementation is no more reliant on Winpthreads * Around 60 new standard library functions * Around 90 various improvements * A dozen of documentation updates * Around 40 bug fixes Please report any unexpected behaviours on the OCaml issue tracker and post any questions or comments you might have on our discussion forums. The full list of changes can be found in the full changelog. --- Installation Instructions The base compiler can be installed as an opam switch with the following commands: opam update opam switch create 5.5.0 The source code for the release is also directly available on: * GitHub * OCaml archives at Inria Fine-Tuned Compiler Configuration If you want to tweak the configuration of the compiler, you can switch to the option variant with: opam update opam switch create ocaml-variants.5.5.0+options where is a space separated list of ocaml-option-* packages. For instance, for a flambda and no-flat-float-array switch: opam switch create 5.5.0+flambda+nffa ocaml-variants.5.5.0+options ocaml-option-flambda ocaml-option-no-flat-float-array

dlvr.it

Wasm_of_ocaml on WASI: A Working Prototype Looking for a Production User

WASI (the WebAssembly System Interface) lets WebAssembly modules run on standalone runtimes, with no browser or JavaScript host required. That opens the door to running OCaml as serverless functions, edge compute, sandboxed plugins, and portable command-line .wasm binaries. A working WASI backend for wasm_of_ocaml, the compiler that turns OCaml into WebAssembly, already exists. It was authored by Jérôme Vouillon as PR #1831. The prototype works today; the one thing missing is a production user to carry it from branch to release. The good news is that WASI itself is a solved problem here: the backend targets WASI preview1, which essentially every runtime supports. The output already runs fully on the Wizard engine today, and on Wasmtime and Node too, with effects compiled via --effects=cps. What unlocks the rest is engine support catching up across the ecosystem. Wasm GC, tail calls, and exception handling are now standardized in Wasm 3.0, but engine support is still maturing; stack switching (used for OCaml's effects) remains a proposal. These features are landing engine by engine, and as support stabilizes OCaml is poised to target the whole class of standalone Wasm runtimes: serverless functions (e.g. Fermyon Spin), plugin sandboxes (e.g. Shopify Functions), edge compute (e.g. Fastly Compute), and portable CLI .wasm binaries (e.g. Wasmer). Since Spin and Fastly are both built on Wasmtime, progress there carries straight through to those platforms. What works today (on the Branch) Compile an OCaml bytecode program for WASI with --enable wasi: wasm_of_ocaml --enable wasi foo.byte -o foo.js The output is the usual foo.js plus a foo.assets/ directory containing the .wasm binary. Run the binary directly on the Wizard engine: wizeng.x86-64-linux --ext:stack-switching foo.assets/code.wasm The same output also runs on wasmtime. The newer exnref-based exception handling is now the default when producing WASI binaries, so no extra compile-time flags are needed: wasm_of_ocaml --enable wasi foo.byte -o foo.js wasmtime -W=all-proposals=y foo.assets/code.wasm The generated foo.js also works as a Node wrapper that runs the WASI binary under Node's WASI support. CI exercises all three paths: Wizard, wasmtime, and Node. Note that effect-using programs need an explicit effects backend: Wizard runs them compiled with --effects=native, while wasmtime and Node need --effects=cps, since neither yet ships GC-integrated stack switching in a stable build. Under the hood, the PR adds around 5,200 lines across 90 files: a WASI-compatible virtual filesystem (fs.wat), Unix bindings covering file operations, process info, time, and permissions, a small libc in libc.c, WASI memory management and errno mapping, and the Node wrapper. It's substantial work, and it's already standing on its own in CI against real runtimes. Status: prototype, on a branch The original work was done as a feasibility study for Jane Street. They wanted to know whether wasm_of_ocaml could realistically target WASI. The answer is yes, and PR #1831 is the result. The native effects PR #2189 it depended on was merged recently, and as far as we know nobody is running WASI-targeted wasm_of_ocaml in production yet. Funding wanted If your team would benefit from running OCaml on standalone Wasm runtimes, this prototype is much closer to production-ready than the "open PR on a branch" status suggests. Tarides is interested in carrying it forward and would like to hear from organizations that could sponsor the work. Reach out at contact@tarides.com, or start a thread on discuss.ocaml.org. See also: Wasm_of_ocaml: What Changed Since 6.1 for the broader picture of where wasm_of_ocaml is headed, including the dynlink/toplevel and native-effects work that landed or is in flight alongside WASI.

dlvr.it

OCamlFormat 0.29.0

We're happy to announce the release of OCamlFormat 0.29.0. CHANGES: Highlight * * Support OCaml 5.5 syntax (#2772, #2774, #2775, #2777, #2780, #2781, #2782, #2783, @Julow) The update brings several tiny changes, they are listed below. * * Update Odoc's parser to 3.0 (#2757, @Julow) The indentation of code-blocks containing OCaml code is reduced by 2 to avoid changing the generated documentation. The indentation within code-blocks is now significative in Odoc and shows up in generated documentation. Added * Added option letop-punning (#2746, @WardBrian) to control whether punning is used in extended binding operators. For example, the code let+ x = x in ... can be formatted as let+ x in ... when letop-punning=always. With letop-punning=never, it becomes let+ x = x in .... The default is preserve, which will only use punning when it exists in the source. This also applies to let%ext bindings (#2747, @WardBrian). * Support the unnamed functor parameters syntax in module types (#2755, #2759, @Julow) module type F = ARG -> S The following lines are now formatted as they are in the source file: module M : (_ : S) -> (_ : S) -> S = N module M : S -> S -> S = N (* The preceding two lines are no longer turned into this: *) module M : (_ : S) (_ : S) -> S = N Fixed * Fix dropped comment in (function _ -> x (* cmt *)) (#2739, @Julow) * * cases-matching-exp-indent=compact does not impact begin end nodes that don't have a match inside. (#2742, @EmileTrotignon) (* before *) begin match () with | () -> begin f x end end (* after *) begin match () with | () -> begin f x end end * Ast_mapper now iterates on all locations inside of Longident.t, instead of only some. (#2737, @v-gb) * Remove line break in M with module N = N (* cmt *) (#2779, @Julow) Internal * Added information on writing tests to CONTRIBUTING.md (#2838, @WardBrian) Changed * indentation of the end keyword in a match-case is now always at least 2. (#2742, @EmileTrotignon) (* before *) begin match () with | () -> begin match () with | () -> () end end (* after *) begin match () with | () -> begin match () with | () -> () * * use shortcut begin end in match cases and if then else body. (#2744, @EmileTrotignon) (* before *) match () with | () -> begin match () with | () -> end end (* after *) match () with | () -> begin match () with | () -> end end * * Set the ocaml-version to 5.4 by default (#2750, @EmileTrotignon) The main difference is that the effect keyword is recognized without having to add ocaml-version=5.3 to the configuration. In exchange, code that use effect as an identifier must use ocaml-version=5.2. * The work to support OCaml 5.5 come with several improvements: * Improve the indentation of let structure-item with the [@ocamlformat "disable"] attribute. let structure-item means let module, let open, let include and let exception. * (let open M in e)[@a] is turned into let[@a] open M in e. * Long let open ... in no longer exceed the margin. * Improve indentation of let structure-item within parentheses: (* before *) (let module M = M in M.foo) (* after *) (let module M = M in M.foo)

dlvr.it

OCaml 5.5.0-beta1

With most developer tools available and the good stability of the compiler, I am happy to announce the first beta release of OCaml 5.5.0. Compared to the last alpha, this new version improves the manpage for ocamlopt and fixes: * two runtime bugs (for ephemerons and the bytecode interpreter) * two type system bugs (for classes and module-dependent functions) * three warning or error message bugs (See the Changelog below for a full list). Concerning the associated compiler tools, most of them are already available (as least in a preview version), and there are patches in progress for the remaining ones. You can track the last remaining update efforts on the release readiness meta-issue. Thus, it should be safe to test your libraries and programs with the new version OCaml 5.5.0 version in preparation of the final release. If everything goes well, we might see a release in May. If you find any bugs, please report them to the GitHub issue tracker. If you are interested by the full list of new features and bug fixes, the changelog for OCaml 5.5.0 is the most up-to-date resource. Happy hacking, Florian Angeletti for the OCaml team. --- Installation Instructions The base compiler can be installed as an opam switch with the following commands on opam 2.1 and later: opam update opam switch create 5.5.0~beta1 The source code for the beta is also available at these addresses: * GitHub: https://github.com/ocaml/ocaml/archive/5.5.0-beta1.tar.gz * OCaml archives at Inria: https://caml.inria.fr/pub/distrib/ocaml-5.5/ocaml-5.5.0~beta1.tar.gz Fine-Tuned Compiler Configuration If you want to tweak the configuration of the compiler, you can switch to the option variant with: opam update opam switch create ocaml-variants.5.5.0~beta1+options where option_list is a space separated list of ocaml-option-* packages. For instance, for a flambda and no-flat-float-array switch: opam switch create 5.5.0~beta1+flambda+nffa ocaml-variants.5.5.0~beta1+options ocaml-option-flambda ocaml-option-no-flat-float-array All available options can be listed with opam search ocaml-option. --- Changes compared to the last alpha Documentation update * #14684: Improve ocamlopt's manual page (Samuel Hym, review by Florian Angeletti) Runtime fixes * #14644, #14647: Fix a bug related to unhandled effects in bytecode. (Vincent Laviron, report by Thibaut Mattio, review by Nicolás Ojeda Bär, Stephen Dolan and Olivier Nicole) * #14349, #14718: runtime, fix in the orphaning of ephemerons (Gabriel Scherer, review by Olivier Nicole and Damien Doligez, report by Jan Midtgaard) Type system fixes * #14557, #12150, #14696: ensure that the self type of class cannot escape through type constraints. (Leo White, review by Florian Angeletti) * #14667: enable application related warnings for module-dependent functions (Florian Angeletti, review by Gabriel Scherer) Error messages and warning fixes * #14690: Fix Name_type_mismatch error message when the expected type is an alias: print the expanded path on the right-hand side of the equality, not the alias twice. (Weixie Cui, review by Florian Angeletti) * #14719, #14721: compute arity correctly for module-dependent function (Florian Angeletti, report by Jeremy Yallop, review by Stefan Muenzel) * #14655, #14691: check for size overflow in caml_ba_reshape (Stephen Dolan, review by Xavier Leroy)

dlvr.it

please participate in the OCaml Users Survey 2026, still open until and including May 25, 2026! link below

OCamlFormat 0.29.0

CHANGES: Highlight * * Support OCaml 5.5 syntax (#2772, #2774, #2775, #2777, #2780, #2781, #2782, #2783, @Julow) The update brings several tiny changes, they are listed below. * * Update Odoc's parser to 3.0 (#2757, @Julow) The indentation of code-blocks containing OCaml code is reduced by 2 to avoid changing the generated documentation. The indentation within code-blocks is now significative in Odoc and shows up in generated documentation. Added * Added option letop-punning (#2746, @WardBrian) to control whether punning is used in extended binding operators. For example, the code let+ x = x in ... can be formatted as let+ x in ... when letop-punning=always. With letop-punning=never, it becomes let+ x = x in .... The default is preserve, which will only use punning when it exists in the source. This also applies to let%ext bindings (#2747, @WardBrian). * Support the unnamed functor parameters syntax in module types (#2755, #2759, @Julow) module type F = ARG -> S The following lines are now formatted as they are in the source file: module M : (_ : S) -> (_ : S) -> S = N module M : S -> S -> S = N (* The preceding two lines are no longer turned into this: *) module M : (_ : S) (_ : S) -> S = N Fixed * Fix dropped comment in (function _ -> x (* cmt *)) (#2739, @Julow) * * cases-matching-exp-indent=compact does not impact begin end nodes that don't have a match inside. (#2742, @EmileTrotignon) (* before *) begin match () with | () -> begin f x end end (* after *) begin match () with | () -> begin f x end end * Ast_mapper now iterates on all locations inside of Longident.t, instead of only some. (#2737, @v-gb) * Remove line break in M with module N = N (* cmt *) (#2779, @Julow) Internal * Added information on writing tests to CONTRIBUTING.md (#2838, @WardBrian) Changed * indentation of the end keyword in a match-case is now always at least 2. (#2742, @EmileTrotignon) (* before *) begin match () with | () -> begin match () with | () -> () end end (* after *) begin match () with | () -> begin match () with | () -> () * * use shortcut begin end in match cases and if then else body. (#2744, @EmileTrotignon) (* before *) match () with | () -> begin match () with | () -> end end (* after *) match () with | () -> begin match () with | () -> end end * * Set the ocaml-version to 5.4 by default (#2750, @EmileTrotignon) The main difference is that the effect keyword is recognized without having to add ocaml-version=5.3 to the configuration. In exchange, code that use effect as an identifier must use ocaml-version=5.2. * The work to support OCaml 5.5 come with several improvements: * Improve the indentation of let structure-item with the [@ocamlformat "disable"] attribute. let structure-item means let module, let open, let include and let exception. * (let open M in e)[@a] is turned into let[@a] open M in e. * Long let open ... in no longer exceed the margin. * Improve indentation of let structure-item within parentheses: (* before *) (let module M = M in M.foo) (* after *) (let module M = M in M.foo)

dlvr.it