Project

General

Profile

« Previous | Next » 

Revision ca7ff3f7

Added by LĂ©lio Brun 8 months ago

reformatting

View differences:

src/utils/env.ml
9 9
(*                                                                  *)
10 10
(********************************************************************)
11 11

  
12
(** Generic inference environments. Used both for typing and
13
    clock-calculus. *)
14 12
open Utils
13
(** Generic inference environments. Used both for typing and clock-calculus. *)
14

  
15
type 'a t = 'a IMap.t
15 16

  
16
type 'a t  = 'a IMap.t
17 17
(* Same namespace for nodes, variables and constants *)
18 18
let initial = IMap.empty
19 19

  
20
let add_value env ident ty =
21
  IMap.add ident ty env
20
let add_value env ident ty = IMap.add ident ty env
22 21

  
23
let lookup_value env ident =
24
  IMap.find ident env
22
let lookup_value env ident = IMap.find ident env
25 23

  
26
let exists_value env ident =
27
  IMap.mem ident env
24
let exists_value env ident = IMap.mem ident env
28 25

  
29 26
let iter env f = IMap.iter f env
27

  
30 28
let fold = IMap.fold
31 29

  
32
(* Merges x and y. In case of conflicting definitions,
33
   overwrites definitions in x by definitions in y *)
30
(* Merges x and y. In case of conflicting definitions, overwrites definitions in
31
   x by definitions in y *)
34 32
let overwrite x y =
35
  IMap.merge (
36
    fun _ _old _new -> match _new with
37
      | Some _ -> _new
38
      | _ -> _old
39
  ) x y
33
  IMap.merge
34
    (fun _ _old _new -> match _new with Some _ -> _new | _ -> _old)
35
    x y
40 36

  
41 37
let pp_env pp_fun fmt env =
42
  let (lid,lty) = list_of_imap env in
38
  let lid, lty = list_of_imap env in
43 39
  let l' = List.combine lid lty in
44
  let pp_fun fmt (id,value) =
45
    Format.fprintf fmt "%s |-> %a" id pp_fun value
46
  in
40
  let pp_fun fmt (id, value) = Format.fprintf fmt "%s |-> %a" id pp_fun value in
47 41
  Format.fprintf fmt "{ @[<v 2>%a@] }" (fprintf_list ~sep:"@," pp_fun) l'
48 42

  
49 43
(* Local Variables: *)

Also available in: Unified diff