+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
+