Benefits of OCaml
Safe
In the context of programming languages, safe programming languages abstract away the details of the machine so that safe programs cannot cause faults at the machine level. For example, safe programs cannot produce segmentation faults (where the machine tries to access a memory location that does not exist or is protected). The C programming language is notoriously unsafe because it allows pointers to memory locations to be manipulated directly. The ML family of languages (including OCaml) are designed to be safe.
There are one or two sources of machine-level faults in OCaml programs. Firstly, using the type-unsafe parts of the language (most notably the Marshal module, for marshalling arbitrary values) is unsafe. Secondly, functions that recurse too deeply and overrun the stack can, on certain architectures (most notably AMD64), incur segmentation faults instead of raising the Stack_overflow exception.
The practical benefits of a safe programming language are enormous. The inability to cause uncontrollable run-time errors (in contrast to controllable "exceptions") and the impossibility of implicitly obtaining pseudo-random data from the machine and ending up with erroneous results eliminates an important class of bugs.
A disadvantage of the approach used by OCaml is that the type of garbage collector (specifically, a copying collector) employed imposes the restriction that references can only be compared for equality and not for inequality (i.e. < and >). In practice, this disadvantage is rarely an issue and, when it is an issue, is easily circumvented (at the cost of performance) by tagging values with unique integers that may then be used to compare the identity of values.
|
Read OCaml for Scientists now!
|
|