Features » Safety

OCaml provides safety features to stop programmers from shipping programs with bugs. This page describes some of these safety features.

Type safety

Static type checking

OCaml enforces type safety rigorously when the program is compiled. Consequently, it isn't possible to compile a program which confuses a string with a number, or one object with another incompatible object.

Type inference

OCaml literally works out the types of every expression and variable in your program, so you don't have to.

You can also change one part of a program and have the compiler tell you which other parts of the program that change affects, even if the change is in a part of the program which doesn't run, such as an obscure error handling routine.

Automatic garbage collection

Garbage collection is the cornerstone of all modern computer languages, and OCaml contains one of the fastest garbage collectors (GC) in any programming language. Forget about the slow, bloated GC in languages like Java. OCaml's GC is nimble and small.

Bounds checking

OCaml automatically enforces array boundaries, and will throw an exception if the program tries to access an element outside the bounds of an array.

When speed matters above all else, you can turn this feature off at compile time.