Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / mlton / env / mono-env.fun
CommitLineData
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
8functor MakeMonoEnv(S: sig
9 structure Env: ENV
10 structure Range: T
11 end): MONO_ENV =
12struct
13
14open S
15open Env
16
17type t = Range.t t
18
19val empty: t = empty()
20
21val equals = equals Range.equals
22
23val layout = layout Range.layout
24
25end
26
27(* THIS ISN'T HERE BECAUSE (no surprise) there is an NJ BUG
28
29functor MonoEnv(S: MONO_ENV_STRUCTS): MONO_ENV =
30 MakeMonoEnv(structure Env = Env(S)
31 structure Range = S.Range)
32*)
33
34functor MonoEnv(S: MONO_ENV_STRUCTS): MONO_ENV =
35BasicEnvToEnv
36(open S
37
38 datatype t = T of (Domain.t * Range.t) List.t
39
40 val fromList = T
41
42 fun toList(T l) = l
43
44 fun equalTo d (d', _) = Domain.equals(d, d')
45
46 fun extend(T drs, d, r) =
47 T(List.cons((d, r), List.remove(drs, equalTo d)))
48
49 fun peek(T l, d) =
50 case List.peek(l, equalTo d) of
51 NONE => NONE
52 | SOME (_, r) => SOME r
53 )