Module KSa := KnotFullSa(TyFSA)(K)(KL).
Definition rmap := K.knot.
Instance Join_rmap: Join rmap := KSa.Join_knot.
Instance Perm_rmap : Perm_alg rmap:= KSa.Perm_knot.
Instance Sep_rmap : Sep_alg rmap:= KSa.Sep_knot.
Instance ag_rmap : ageable rmap := K.ageable_knot.
Instance Age_rmap: Age_alg rmap := KSa.asa_knot.
Inductive preds : Type :=
SomeP : forall A : TypeTree,
(forall ts: list Type, dependent_type_functor_rec ts A (pred rmap)) -> preds.
Definition NoneP := SomeP (ConstType unit) (fun _ => tt).
Inductive resource : Type :=
| NO: forall sh: Share.t, ~ readable_share sh -> resource
| YES: forall sh: Share.t, readable_share sh -> kind -> preds -> resource
| PURE: kind -> preds -> resource.
Definition resource2res (r: resource): res (pred rmap) :=
match r with
| NO sh nsh => NO' (pred rmap) sh nsh
| YES sh rsh k (SomeP A l) => YES' (pred rmap) sh rsh k (existT _ A l)
| PURE k (SomeP A l) => PURE' (pred rmap) k (existT _ A l)
end.
Definition res2resource (r: res (pred rmap)) : resource :=
match r with
| NO' sh nsh => NO sh nsh
| YES' sh rsh k (existT A l) => YES sh rsh k (SomeP A l)
| PURE' k (existT A l) => PURE k (SomeP A l)
end.
Definition ghost : Type := list (option ({g: Ghost & {a: @G g | ghost.valid a}} * preds)%type).
Definition pred2p (p: preds) : fpreds (pred rmap) :=
match p with SomeP A P => existT _ A P end.
Definition p2pred (p: fpreds (pred rmap)) : preds :=
match p with existT A P => SomeP A P end.
Definition ghost2g (r: ghost): SM.ghost (pred rmap) :=
map (option_map (fun '(a, b) => (a, pred2p b))) r.
Definition g2ghost (r: SM.ghost (pred rmap)) : ghost :=
map (option_map (fun '(a, b) => (a, p2pred b))) r.

Lemma ghost2g2ghost: forall x, g2ghost (ghost2g x) = x.