1 (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
8 functor BasicEnvToEnv(S: BASIC_MONO_ENV): MONO_ENV =
13 val isEmpty = List.isEmpty o toList
18 align(List.map(toList e, fn (d, r) =>
19 seq[Domain.layout d, str " -> ", Range.layout r])),
23 val size = List.length o toList
25 val empty = fromList []
27 fun domain e = List.revMap (toList e, #1)
29 fun single(d, r) = extend(empty, d, r)
31 fun new (ds, f) = fromList (List.map (ds, fn d => (d, f d)))
33 fun map (e, f) = fromList (List.map (toList e, fn (d, r) => (d, f r)))
35 fun mapi (e, f) = fromList (List.map(toList e, fn (d, r) => (d, f(d, r))))
38 List.fold (toList env', env, fn ((d, r), env) => extend (env, d, r))
40 fun plus es = List.fold(es, empty, fn (e, accum) => accum + e)
42 val plus = Trace.trace("BasicEnvToEnv.plus", List.layout layout, layout) plus
45 fromList(List.remove(toList env, fn (d', _) => Domain.equals(d, d')))
47 fun lookup(env, d) = case peek(env, d) of
49 | NONE => (Layout.output(Domain.layout d, Out.error) ;
50 Out.newline Out.error ;
51 Error.bug "BasicEnvToEnv.lookup")
53 fun restrict(env, ds) = new(ds, fn d => lookup(env, d))
55 fun multiExtend(env, ds, rs) =
58 | (d :: ds, r :: rs) => multiExtend(extend(env, d, r), ds, rs)
59 | _ => Error.bug "BasicEnvToEnv.multiExtend"
61 fun fold(e, b, f) = List.fold(toList e, b, fn ((_, r), b) => f(r, b))
62 fun foldi(e, b, f) = List.fold(toList e, b, fn ((d, r), b) => f(d, r, b))
64 fun foreach(e, f) = List.foreach(toList e, f o #2)
65 fun foreachi(e, f) = List.foreach(toList e, f)
67 fun foralli(e, f) = List.forall(toList e, f)
72 andalso foralli(e1, fn (d, r) =>
75 | SOME r' => Range.equals(r, r'))