About the OCaml compiler
Functional with great performance. Compiled online. Run OCaml code in your browser with no install and no signup — the editor, the input and the output share one screen. OCaml is executed by a remote runtime: your code is submitted to it and the output is returned to this page.
Press Run to execute the program, edit it and press Run again, or paste your own code over it. Everything you type stays in the page; the editor caches your work locally so a reload does not lose it.
A OCaml example
This is the program the OCaml editor opens with — run it as it is, then change it.
(* Pattern matching & records *)
type student = { name: string; score: int }
let students = [
{ name = "Alice"; score = 92 };
{ name = "Bob"; score = 87 };
{ name = "Charlie"; score = 95 };
{ name = "Diana"; score = 88 };
]
let grade s = match s with
| s when s >= 90 -> "A"
| s when s >= 80 -> "B"
| s when s >= 70 -> "C"
| _ -> "D"
let () =
Printf.printf "OCaml Student Report\n\n";
let sorted = List.sort (fun a b -> compare b.score a.score) students in
List.iteri (fun i s ->
Printf.printf " %d. %-10s %d [%s]\n" (i+1) s.name s.score (grade s.score)
) sorted;
let total = List.fold_left (fun acc s -> acc + s.score) 0 students in
let avg = float_of_int total /. float_of_int (List.length students) in
Printf.printf "\nAverage: %.1f\n" avg;
(* Higher-order *)
let names = List.map (fun s -> s.name) students in
The editor opens with the full program.
More Functional compilers
Browse all 109 languages — the same editor runs each of them, in the browser or on a shared runner.