Module Type RMAPS.
Declare Module AV:ADR_VAL.
Parameter rmap : Type.
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 res_option (r:resource) : option (rshare * kind) :=
match r with
| NO _ _ => None
| YES sh rsh k _ => Some (readable_part rsh,k)
| PURE k _ => None
end.
Inductive res_join : resource -> resource -> resource -> Prop :=
| res_join_NO1 : forall sh1 nsh1 sh2 nsh2 sh3 nsh3
(RJ: join sh1 sh2 sh3),
res_join (NO sh1 nsh1) (NO sh2 nsh2) (NO sh3 nsh3)
| res_join_NO2 : forall sh1 rsh1 sh2 nsh2 sh3 rsh3 k p
(RJ: join sh1 sh2 sh3),
res_join (YES sh1 rsh1 k p) (NO sh2 nsh2) (YES sh3 rsh3 k p)
| res_join_NO3 : forall sh1 nsh1 sh2 rsh2 sh3 rsh3 k p
(RJ: join sh1 sh2 sh3),
res_join (NO sh1 nsh1) (YES sh2 rsh2 k p) (YES sh3 rsh3 k p)
| res_join_YES : forall sh1 rsh1 sh2 rsh2 sh3 rsh3 k p
(RJ: join sh1 sh2 sh3),
res_join (YES sh1 rsh1 k p) (YES sh2 rsh2 k p) (YES sh3 rsh3 k p)
| res_join_PURE : forall k p, res_join (PURE k p) (PURE k p) (PURE k p).
Instance Join_resource: Join resource := res_join.
Definition preds_fmap (f g: pred rmap -> pred rmap) (x:preds) : preds :=
match x with SomeP A Q => SomeP A (fmap (fpi _) f g Q)
end.
Definition resource_fmap (f g:pred rmap -> pred rmap) (x:resource) : resource :=
match x with
| NO sh nsh => NO sh nsh
| YES sh rsh k p => YES sh rsh k (preds_fmap f g p)
| PURE k p => PURE k (preds_fmap f g p)
end.

Axiom resource_fmap_id : resource_fmap (id _) (id _) = id resource.
Axiom resource_fmap_comp : forall f1 f2 g1 g2,
resource_fmap g1 g2 oo resource_fmap f1 f2 = resource_fmap (g1 oo f1) (f2 oo g2).