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
Miscellaneous OCaml Code
OCaml Resources
As always, please contact us with comments, concerns, questions, etc. about OCaml!

OCaml 101

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



OCaml Resources

This section will have OCaml related links…

Leave a Reply