<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.26">
<title>TypeConstructor</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="./mlton.css">

</head>
<body class="article">
<div id="mlton-header">
<div id="mlton-header-text">
<h2>
<a href="./Home">
MLton
20241230+git20251029+dfsg-5
</a>
</h2>
</div>
</div>
<div id="header">
<h1>TypeConstructor</h1>
</div>
<div id="content">
<div class="paragraph">
<p>In <a href="StandardML">Standard ML</a>, a type constructor is a function from
types to types.  Type constructors can be <em>nullary</em>, meaning that
they take no arguments, as in <code>char</code>, <code>int</code>, and <code>real</code>.
Type constructors can be <em>unary</em>, meaning that they take one
argument, as in <code>array</code>, <code>list</code>, and <code>vector</code>.  A program
can define a new type constructor in two ways: a <code>type</code> definition
or a <code>datatype</code> declaration.  User-defined type constructors can
can take any number of arguments.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">datatype t = T of int * real            (* 0 arguments *)
type 'a t = 'a * int                    (* 1 argument *)
datatype ('a, 'b) t = A | B of 'a * 'b  (* 2 arguments *)
type ('a, 'b, 'c) t = 'a * ('b  -&gt; 'c)  (* 3 arguments *)</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here are the syntax rules for type constructor application.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Type constructor application is written in postfix.  So, one writes
<code>int list</code>, not <code>list int</code>.</p>
</li>
<li>
<p>Unary type constructors drop the parens, so one writes
<code>int list</code>, not <code>(int) list</code>.</p>
</li>
<li>
<p>Nullary type constructors drop the argument entirely, so one writes
<code>int</code>, not <code>() int</code>.</p>
</li>
<li>
<p>N-ary type constructors use tuple notation; for example,
<code>(int, real) t</code>.</p>
</li>
<li>
<p>Type constructor application associates to the left.  So,
<code>int ref list</code> is the same as <code>(int ref) list</code>.</p>
</li>
</ul>
</div>
</div>
</body>
</html>