OCaml

This page contains basic beginner and more advanced OCaml snippets; the purpose of this page is for those who are learning and like to learn (via pure code), as well as, a location for mpettersson to keep snippets and OCaml related links. In the spirit of full disclosure and the students comprehension, OCaml is not a language you can feasibly pickup via syntax alone (given that you don’t know Haskell or any other functional languages). We would strongly suggest utilizing the OCaml site for descriptions and tutorials that best represent all of the subtleties and nuances of OCaml. This pages subsections are:

 

OCaml 101

The general and technical programming language aspects of OCaml are:

Uses: Application (theorem provers, compilers, interpreters)
Website: ocaml.org
Get Started: ocaml.org/learn
Download: ocaml.org/docs/install
Documents: ocaml.org/docs
Developer: INRIA
First Released: 1996
Implementation: Compiled (compiler offers a top-level interactive loop)
Type Safety: Strong
Type System: Implicit
Type Checking: Static
Imperative: Yes
Aspect Oriented: No
Object Oriented: Yes
Functional: Yes
Procedural: Yes
Generic: Yes
Standardized: Yes (PEPs)
Failsafe I/O: Yes
Garbage Collected: Yes

There is really only one link to remember for all things OCaml: https://ocaml.org/ (no, really, it has everything you’ll need…).

 

OCaml Keywords
and as assert begin class constraint
do done downto else end exception
external false for fun function functor
if in include inherit inherit! initializer
lazy let match method method! module
mutable new object of open or
private rec sig struct then to
true try type val val! virtual
when while with

The following snippet, OCaml 101, contains examples of basic OCaml. Note that the lines beginning with a hash or pound (#) sign represents the OCaml interpreter and that the lines not beginning with a pound represent the output (from the OCaml interpreter). The majority of these examples came from Dr. Hamlen’s OCaml slides (our favorite professor at UTD).

 

Miscellaneous OCaml Code

The following are miscellaneous snippets of OCaml code:

 

OCaml Resources

This section will have OCaml related links, for now just use https://ocaml.org/.

 

As always, please contact us with comments, concerns, questions, etc. about OCaml!