X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_notation%2FcicNotationEnv.ml;h=749e9148b979e7d7a137fef76f4968f556767afb;hb=8caaccfeb66f6a507e5fb3b4b221a360eb5428c8;hp=13920157ec8c9ddee9313c69758e4e8877331616;hpb=e9cfecee7dd7cf8388512ffd4aa223782c728eda;p=helm.git diff --git a/helm/ocaml/cic_notation/cicNotationEnv.ml b/helm/ocaml/cic_notation/cicNotationEnv.ml index 13920157e..749e9148b 100644 --- a/helm/ocaml/cic_notation/cicNotationEnv.ml +++ b/helm/ocaml/cic_notation/cicNotationEnv.ml @@ -50,6 +50,8 @@ let lookup_value env name = snd (List.assoc name env) with Not_found -> raise (Value_not_found name) +let remove env name = List.remove_assoc name env + let lookup_term env name = match lookup_value env name with | TermValue x -> x @@ -72,3 +74,50 @@ let list_binding_of_name (n, ty) = (n, (ListType ty, ListValue [])) let opt_declaration (n, ty) = (n, OptType ty) let list_declaration (n, ty) = (n, ListType ty) +let declaration_of_var = function + | NumVar s -> s, NumType + | IdentVar s -> s, StringType + | TermVar s -> s, TermType + | _ -> assert false + +let value_of_term = function + | Num (s, _) -> NumValue s + | Ident (s, None) -> StringValue s + | t -> TermValue t + +let term_of_value = function + | NumValue s -> Num (s, 0) + | StringValue s -> Ident (s, None) + | TermValue t -> t + | _ -> assert false (* TO BE UNDERSTOOD *) + +let rec well_typed ty value = + match ty, value with + | TermType, TermValue _ + | StringType, StringValue _ + | OptType _, OptValue None + | NumType, NumValue _ -> true + | OptType ty', OptValue (Some value') -> well_typed ty' value' + | ListType ty', ListValue vl -> + List.for_all (fun value' -> well_typed ty' value') vl + | _ -> false + +let declarations_of_env = List.map (fun (name, (ty, _)) -> (name, ty)) + +let coalesce_env declarations env_list = + let env0 = List.map list_binding_of_name declarations in + let grow_env_entry env n v = + List.map + (function + | (n', (ty, ListValue vl)) as entry -> + if n' = n then n', (ty, ListValue (v :: vl)) else entry + | _ -> assert false) + env + in + let grow_env env_i env = + List.fold_left + (fun env (n, (_, v)) -> grow_env_entry env n v) + env env_i + in + List.fold_right grow_env env_list env0 +