OCaml By Examples

Language Basics

Project Management

  • dune
  • dune-release
  • opam pin

Advanced Ocaml

  • functors
  • monads

Libraries

Show

main.ml

open Core

type person = { name: string ; age: int ; human : bool }
[@@deriving show]

let () =
  let human_one = { name = "david" ; age = 32 ; human = false } in
  printf "%s\n" (show_person human_one)

dune

(executable
 (name main)
 (libraries core)
 (preprocess
  (pps ppx_deriving.show)))

console

$ opam install base ppx_deriving
$ dune exec ./main.exe
{ Main.name = "david"; age = 32; human = false }
next: bin_prot