Polymorphic types in OCaml
www2.lib.uchicago.edu
www2.lib.uchicago.edu
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.
To familiarize with the Syntax, see: http://rigaux.org/language-study/syntax-across-languages-per...
To get a quick hang of the language, try: http://learnxinyminutes.com/docs/ocaml/
---- OCaml REPL in your browser: http://try.ocamlpro.com/