HCODX |

Online OCaml Compiler Runner (Editor, Interpreter)

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to HCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

Why Use Our Free OCaml?

Online OCaml Compiler with an Interactive Terminal

Compile and run OCaml code online instantly with HCODX. Our free cloud-based OCaml compiler supports real-time execution, standard input, syntax highlighting, and code download. No installation or configuration required. Start coding in OCaml now.

Instant Execution

Run OCaml instantly without installing any IDEs or configuring environments. Our cloud-based OCaml handles libraries, runtimes, and dependencies automatically so you can focus on writing code.

Perfect for Learning

Whether you are studying algorithms in OCaml, practicing data structures in OCaml, or exploring functional programming, our tool provides real-time stdout/stderr feedback with interactive standard input support.

Professional Features

  • Standard Input (stdin) support
  • 85+ programming languages
  • Syntax highlighting with themes
  • Zero-setup cloud environment
  • Download code as .ml
  • Real-time compilation & execution

Why developers use HCODX

HCODX is a free online compiler and code runner: write code in your browser, execute it on a cloud sandbox, and interact with your program through a live terminal. Students use it for coursework and interview practice; developers use it to test snippets in 85+ languages without setting up a local environment.

About OCaml

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.

Hello World in OCaml

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."

When to use OCaml

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. HCODX is a free online OCaml editor, runner and interpreter — an IDE-grade compiler and playground to write and run code online, execute code with live output and live preview, no downloads or web server required.

Common questions

Why use %! in printf, and does read_line really wait for me?

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.

Which OCaml version is this, and is it compiled?

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.

Can I use opam libraries like Core or Lwt?

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.