OCaml By Examples

Language Basics

Project Management

  • dune
  • dune-release
  • opam pin

Advanced Ocaml

  • functors
  • monads

Libraries

Values

utop

The integer type can contain numbers from -4611686018427387904 to 4611686018427387903.
utop # 1 + 1;;
- : int = 2

utop # 1.3 +. 2.5;;
- : float = 3.8

utop # 1 lsl 3;;
- : int = 8

utop # 3 > 5;;
- : bool = false

utop # "hello" ^ " world";;
- : string = "hello world"

utop # let a = 1;;
val a : int = 1

utop # let add_one i = i + 1;;
val add_one : int -> int = <fun>

utop # let a' = add_one a;;
val a' : int = 2

utop # Int.( * ) 2 3;;
- : int = 6

utop # Int.( = ) 3 5;;
- : bool = false
If you see an operator you haven't seen before, you can check what it is on the [operator lookup](https://www.craigfe.io/operator-lookup/) page.
next: Match