What is a .ml file?
OCaml Source File · Code and data · INRIA · 1996
An .ml file is OCaml source code, a functional language from the ML family with a powerful type system and a fast native compiler. It is used in finance, compilers and formal verification.
What is a .ml file used for?
OCaml descends from ML, the language family that pioneered type inference: the compiler works out the types so code stays concise but statically checked. Trading firms, proof assistants like Coq, and compiler projects rely on it.
An .ml file holds implementation; an .mli file is its interface, declaring what the module exposes. The files are plain text.
What opens a .ml file?
The .ml format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.
Windows
- VS Code (OCaml Platform)
- any text editor
macOS
- VS Code (OCaml Platform)
- any text editor
Linux
- VS Code (OCaml Platform)
- Emacs (tuareg)
- any text editor
Open a .ml file step by step
- Confirm the file really is a .ml. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with VS Code (OCaml Platform) or any text editor.
- On Mac, use VS Code (OCaml Platform) or any text editor.
- On Linux, try VS Code (OCaml Platform) or Emacs (tuareg).
- Still stuck? Convert the .ml to exe (native, via dune), which opens more widely.
Why can't I open my .ml file?
Almost always because no installed app understands OCaml. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .ml at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
How to convert a .ml file
You can convert a .ml file to exe (native, via dune) using a conversion tool or the export menu of an app that opens it.
OCaml has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.
Frequently asked questions
What is a .ml file?
An .ml file is OCaml source code, a functional language from the ML family with a powerful type system and a fast native compiler. It is used in finance, compilers and formal verification.
How do I run an .ml file?
Use the OCaml toplevel (ocaml file.ml) for quick scripts, or build a project with dune, the standard OCaml build tool.
What is the difference between .ml and .mli?
The .ml file contains a module's implementation; the matching .mli file is its interface, listing exactly which types and functions other code may see.
Is .ml ever something other than OCaml?
Occasionally it holds Standard ML, the older sibling language. If the code uses let ... in and pattern matching with OCaml's syntax and operators, it is OCaml.
Related formats
Sources
Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.