Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Jane Street trades billions of dollars a day on OCaml code — probably the strongest industrial endorsement any functional language has ever received. OCaml pairs an expressive ML-family type system (inference, variants, exhaustive pattern matching) with a pragmatic streak: mutation and imperative loops are allowed when you want them, and the native compiler produces genuinely fast binaries. The OCaml 5.x era brought a multicore runtime with effect handlers, modernizing its concurrency story. Beyond finance, OCaml built the Rocq (Coq) proof assistant and early Docker tooling, and it anchors compilers-and-PL curricula at many universities. Run OCaml here in an interactive terminal — read_line takes your keyboard input live, with the toolchain already set up server-side.
let rec fact = function
| 0 -> 1
| k -> k * fact (k - 1)
let () =
Printf.printf "What's your name? %!";
let name = read_line () in
Printf.printf "Hello, %s!\n" name;
Printf.printf "Enter a small integer: %!";
let n = int_of_string (String.trim (read_line ())) in
Printf.printf "%d! = %d\n" n (fact n);
match n mod 2 with
| 0 -> print_endline "You picked an even number."
| _ -> print_endline "You picked an odd number."
OCaml is a staple of compilers and programming-languages courses — its variants and pattern matching make ASTs and interpreters almost pleasant to write, which is why courses at Cornell (CS 3110), Cambridge, and elsewhere teach it. It's also the language of Jane Street's famously selective interviews, so candidates drill list recursion, fold, and module basics beforehand. This page suits both: work through '99 Problems in OCaml,' test a pattern match for exhaustiveness, or prototype an evaluator without installing opam and dune on a lab machine.
read_line blocks until you type a line — this is a live terminal session. The %! conversion in Printf flushes stdout, which matters because OCaml buffers output: without it, a prompt lacking a newline might not appear before the program pauses for input. The example uses %! on every prompt for that reason.
Code runs on a modern OCaml from the 5.x era — the multicore-capable runtime — using the standard toolchain, so what compiles here compiles locally. Type errors, warnings about non-exhaustive matches, and runtime behavior all match a regular ocaml installation; you're writing ordinary single-file OCaml.
No — there's no opam in the sandbox, so Jane Street's Core, Lwt, and other external libraries aren't importable. You get the official standard library: List, Array, Hashtbl, String, Printf, Buffer, and friends. Coursework and interview problems are conventionally solved with exactly that, so the limitation rarely bites.
main.mlmllikeread_line()print_endline "Hello from OCaml!";;
print_endline "Welcome to XCODX Online Compiler!";;
let message = "OCaml is functional!";;
print_endline message;;