implicitt/lib/Core/Metaenv.ml

34 lines
793 B
OCaml
Raw Normal View History

2023-02-01 14:38:14 +01:00
module C = Common
module V = Value
module Mv =
struct
type t = C.meta
let compare (C.Mv i1) (C.Mv i2) = Stdlib.compare i1 i2
end
module MvMap = Map.Make(Mv)
2023-02-01 14:38:14 +01:00
2023-02-04 16:58:16 +01:00
type mentry
= Unsolved of V.value (* type *)
| Solved of (V.value * V.value) (* solution : type *)
2023-02-01 14:38:14 +01:00
let metaEntries : mentry MvMap.t ref = ref MvMap.empty
let getMetaEntry (m : C.meta) =
MvMap.find m !metaEntries
2023-02-01 14:38:14 +01:00
let modMetaEntry (f : mentry MvMap.t -> mentry MvMap.t) =
metaEntries.contents <- f !metaEntries
2023-02-01 14:38:14 +01:00
(* TODO: if not found then insert new meta for the type somehow *)
let getMetaType (m : C.meta) =
match getMetaEntry m with
2023-02-04 16:58:16 +01:00
| Unsolved ty -> ty
| Solved (_, ty) -> ty
let resolveMeta (m : C.meta) =
match getMetaEntry m with
| Unsolved ty -> V.Stuck (V.Meta m, ty)
2023-02-04 16:58:16 +01:00
| Solved (tr, _) -> tr