<!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>Utilities</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>Utilities</h1>
</div>
<div id="content">
<div class="paragraph">
<p>This page is a collection of basic utilities used in the examples on
various pages.  See</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="InfixingOperators">InfixingOperators</a>, and</p>
</li>
<li>
<p><a href="ProductType">ProductType</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>for longer discussions on some of these utilities.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="sml">(* Operator precedence table *)
infix   8  * / div mod        (* +1 from Basis Library *)
infix   7  + - ^              (* +1 from Basis Library *)
infixr  6  :: @               (* +1 from Basis Library *)
infix   5  = &lt;&gt; &gt; &gt;= &lt; &lt;=     (* +1 from Basis Library *)
infix   4  &lt;\ \&gt;
infixr  4  &lt;/ /&gt;
infix   3  o
infix   2  &gt;|
infixr  2  |&lt;
infix   1  :=                 (* -2 from Basis Library *)
infix   0  before &amp;

(* Some basic combinators *)
fun const x _ = x
fun cross (f, g) (x, y) = (f x, g y)
fun curry f x y = f (x, y)
fun fail e _ = raise e
fun id x = x

(* Product type *)
datatype ('a, 'b) product = &amp; of 'a * 'b

(* Sum type *)
datatype ('a, 'b) sum = INL of 'a | INR of 'b

(* Some type shorthands *)
type 'a uop = 'a -&gt; 'a
type 'a fix = 'a uop -&gt; 'a
type 'a thunk = unit -&gt; 'a
type 'a effect = 'a -&gt; unit
type ('a, 'b) emb = ('a -&gt; 'b) * ('b -&gt; 'a)

(* Infixing, sectioning, and application operators *)
fun x &lt;\ f = fn y =&gt; f (x, y)
fun f \&gt; y = f y
fun f /&gt; y = fn x =&gt; f (x, y)
fun x &lt;/ f = f x

(* Piping operators *)
val op&gt;| = op&lt;/
val op|&lt; = op\&gt;</code></pre>
</div>
</div>
</div>
</body>
</html>