Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 1999-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh |
2 | * Jagannathan, and Stephen Weeks. | |
3 | * | |
4 | * MLton is released under a BSD-style license. | |
5 | * See the file MLton-LICENSE for details. | |
6 | *) | |
7 | (*------------------------------------------------------------------*) | |
8 | (* BoundedOrder *) | |
9 | (*------------------------------------------------------------------*) | |
10 | ||
11 | functor BoundedOrder(O: ORDER): BOUNDED_ORDER = | |
12 | struct | |
13 | ||
14 | structure O = O | |
15 | structure R = Relation | |
16 | ||
17 | datatype t = | |
18 | Min | |
19 | | Max | |
20 | | Inject of O.t | |
21 | ||
22 | val smallest = Min | |
23 | val largest = Max | |
24 | val inject = Inject | |
25 | ||
26 | val project = | |
27 | fn Inject x => x | |
28 | | _ => Error.bug "BoundedOrder.project" | |
29 | ||
30 | val compare = | |
31 | fn (Min, Min) => R.EQUAL | |
32 | | (Min, _) => R.LESS | |
33 | | (Max, Max) => R.EQUAL | |
34 | | (Max, _) => R.GREATER | |
35 | | (Inject _, Min) => R.GREATER | |
36 | | (Inject _, Max) => R.LESS | |
37 | | (Inject x, Inject y) => O.compare(x, y) | |
38 | ||
39 | val {equals, <, <=, >, >=, min, max} = R.compare compare | |
40 | ||
41 | local open Layout | |
42 | in fun layout x = | |
43 | case x of | |
44 | Min => str "Min" | |
45 | | Max => str "Max" | |
46 | | Inject x => O.layout x | |
47 | end | |
48 | ||
49 | end |