Introduction

Why OCaml?

OCaml is a statically typed functional programming language with a powerful type system, automatic memory management, and native code compilation. It is the language behind tools like the Coq proof assistant, MirageOS, and the original implementation of Rust's compiler.

  • Strong type inference — OCaml infers types so you rarely need annotations, yet the compiler catches errors at compile time.
  • Pattern matching — exhaustive pattern matching makes it easy to handle every case in your data.
  • Algebraic data types — variants and records let you model complex domains precisely.
  • Functional core, imperative when needed — OCaml is functional-first but supports mutable state and imperative loops.
  • Fast native compilation — OCaml compiles to efficient native code, with performance competitive with C.

What You Will Learn

  • Printing output with print_endline, print_int, and print_newline
  • Immutable bindings with let
  • Basic types: int, float, string, bool
  • Arithmetic and type conversions
  • Defining and calling functions
  • Recursion with let rec
  • Higher-order functions and fun lambdas
  • Lists with [...], ::, and the List module
  • Tuples and fst/snd
  • Pattern matching with match ... with
  • The option type (Some/None)
  • Modules and the pipe operator |>

Resources

Next →