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.
OCaml is a statically typed language from the ML family that blends functional, imperative, and object-oriented styles under one type system with full type inference. It grew out of the Caml project at France's INRIA institute, with the Objective Caml release arriving in 1996 under Xavier Leroy and colleagues. Its type checker catches many errors at compile time without requiring type annotations, and its native compiler is known for fast code. OCaml is used where correctness and performance both matter: the Jane Street trading firm builds most of its systems in it, the first Rust compiler was written in it, and tools like Facebook's Flow and the Coq proof assistant are built on it. On XCODX, OCaml runs in a cloud sandbox through the ocaml interpreter, so you can try the language and its standard library without installing opam or a build tool.
(* OCaml stdlib: read a line, then fold a list *)
let () =
print_string "What is your name? ";
let name = read_line () in
Printf.printf "Hello, %s!\n" name;
let total = List.fold_left ( + ) 0 [1; 2; 3; 4; 5] in
Printf.printf "Sum of 1..5 is %d\n" total
OCaml fits problems where you want strong compile-time guarantees and native-code speed at the same time, such as compilers, static analyzers, theorem provers, and low-latency financial systems. Pattern matching over algebraic data types makes modeling complex states concise, and the compiler checks that matches are exhaustive. Its module system supports large codebases with clear interfaces. It is a less obvious pick for quick scripting or teams that need a large ready-made library ecosystem, since its package set is smaller than those of Python or JavaScript.
read_line () returns the next line from standard input as a string, Scanf.scanf reads typed values with a format such as %d, and read_int () parses a whole line as an int. On XCODX you can type into the live terminal or paste into the Stdin Box up front, and Ctrl+D closes the stream.
No. The sandbox runs a single file against the OCaml standard library only and has no network access, so there is no opam and no dune build. Packages like Core, Base, or Lwt cannot be fetched; use stdlib modules such as List, Array, String, Printf, and Scanf.
It runs through the ocaml interpreter, which evaluates the file rather than producing a standalone native binary the way ocamlopt would. You still get full type checking before execution, so type errors stop the program before any output appears.
OCaml is statically typed with type inference, so the whole file is checked before it runs. A mismatch, such as passing a string where an int is expected or a non-exhaustive match, is reported at compile time with a location, and nothing executes until it is fixed.
Output is buffered, so a prompt printed with print_string may not show until the buffer flushes; call flush stdout before reading to force it out. print_string writes without a trailing newline, print_endline adds one, and Printf.printf uses format strings.
The OCaml version is shown in the badge next to the editor. It is free with no signup and no local install, and each run starts from a fresh sandbox with no saved files.
main.mlmllikeread_line()print_endline "Hello from OCaml!";;
print_endline "Welcome to XCODX Online Compiler!";;
let message = "OCaml is functional!";;
print_endline message;;