

Polymorphic types in OCaml - panamafrank
http://www2.lib.uchicago.edu/keith/ocaml-class/userdefined.html

======
CHY872
As a correction, it's wrong to describe OCaml's types as being polymorphic (I
expected this to be polymorphic types in OCaml, which would have been far more
interesting!)

All of the _types_ used by OCaml are monomorphic. The _expressions_ written in
OCaml are polymorphic - they can have multiple types.

An expression like:

fn f => (f true) :: (f nil)

is untypeable in OCaml; f must have some type tau -> tau', applying it to true
means that tau = bool, applying to nil means that tau = a list, and a list <>
bool.

The expression itself can have many types; we choose the type we care about
based on context.

Polymorphic types mean that one type can be many things; one could use them to
(for example, if we allowed forall quantifiers) prove that function to be of
type (forall alpha.alpha -> alpha) -> bool list.

This turns out to be undecidable for languages like OCaml, but simpler
languages (usually ones that admit no nontermination) sometimes allow it.

------
ignoramous
For any one interested in OCaml, you'd find that
[https://realworldocaml.org/v1/en/html/a-guided-
tour.html](https://realworldocaml.org/v1/en/html/a-guided-tour.html) is an
excellent introduction to the language.

To familiarize with the Syntax, see: [http://rigaux.org/language-study/syntax-
across-languages-per...](http://rigaux.org/language-study/syntax-across-
languages-per-language/OCaml.html)

To get a quick hang of the language, try:
[http://learnxinyminutes.com/docs/ocaml/](http://learnxinyminutes.com/docs/ocaml/)

\---- OCaml REPL in your browser:
[http://try.ocamlpro.com/](http://try.ocamlpro.com/)

