Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / basic / sum.fun
CommitLineData
7f918cf1
CE
1(* Copyright (C) 1999-2005 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
8functor Sum(S: SUM_STRUCTS): SUM =
9struct
10
11open S
12
13datatype t =
14 X of X.t
15 | Y of Y.t
16
17val outX =
18 fn X x => x
19 | _ => Error.bug "Sum.outX"
20
21val outY =
22 fn Y y => y
23 | _ => Error.bug "Sum.outY"
24
25val map =
26 fn (X x, f, _) => f x
27 | (Y y, _, f) => f y
28
29val equals =
30 fn (X l, X l') => X.equals(l, l')
31 | (Y l, Y l') => Y.equals(l, l')
32 | _ => false
33
34fun layout s = map(s, X.layout, Y.layout)
35
36end