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.
How to open 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. For a step-by-step walkthrough, see how to open a .ml file.
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
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.
.ml file signature (magic bytes)
Programs recognise a .ml file by the bytes at the start of the file, not by its name. These are the signatures for OCaml.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
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: