MLton MLTONWIKIVERSION

Utilities

Home Index

This page is a collection of basic utilities used in the examples on various pages. See

- InfixingOperators, and

- ProductType

for longer discussions on some of these utilities.

    (* 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  = <> > >= < <=     (* +1 from Basis Library *)
    infix   4  <\ \>
    infixr  4  </ />
    infix   3  o
    infix   2  >|
    infixr  2  |<
    infix   1  :=                 (* -2 from Basis Library *)
    infix   0  before &

    (* 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 = & of 'a * 'b

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

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

    (* Infixing, sectioning, and application operators *)
    fun x <\ f = fn y => f (x, y)
    fun f \> y = f y
    fun f /> y = fn x => f (x, y)
    fun x </ f = f x

    (* Piping operators *)
    val op>| = op</
    val op|< = op\>

Last edited on 2006-08-13 14:40:14 by VesaKarvonen.