Skip to content
Snippets Groups Projects
Commit 712e8666 authored by Robbert Krebbers's avatar Robbert Krebbers
Browse files

Countable instances for pmap and gmap.

(These instances are not defined for any FinMap to avoid overlapping
instances for EqDecision, which may have awkward consequences for
type class search).
parent 632b3dad
No related branches found
No related tags found
No related merge requests found
...@@ -112,6 +112,16 @@ Proof. ...@@ -112,6 +112,16 @@ Proof.
by rewrite lookup_merge by done; destruct (m1 !! _), (m2 !! _). by rewrite lookup_merge by done; destruct (m1 !! _), (m2 !! _).
Qed. Qed.
Program Instance gmap_countable
`{Countable K, Countable A} : Countable (gmap K A) := {
encode m := encode (map_to_list m : list (K * A));
decode p := map_of_list <$> decode p
}.
Next Obligation.
intros K ?? A ?? m; simpl. rewrite decode_encode; simpl.
by rewrite map_of_to_list.
Qed.
(** * Finite sets *) (** * Finite sets *)
Notation gset K := (mapset (gmap K)). Notation gset K := (mapset (gmap K)).
Instance gset_dom `{Countable K} {A} : Dom (gmap K A) (gset K) := mapset_dom. Instance gset_dom `{Countable K} {A} : Dom (gmap K A) (gset K) := mapset_dom.
......
...@@ -8,7 +8,7 @@ However, we extend Leroy's implementation by packing the trees into a Sigma ...@@ -8,7 +8,7 @@ However, we extend Leroy's implementation by packing the trees into a Sigma
type such that canonicity of representation is ensured. This is necesarry for type such that canonicity of representation is ensured. This is necesarry for
Leibniz equality to become extensional. *) Leibniz equality to become extensional. *)
From Coq Require Import PArith. From Coq Require Import PArith.
From iris.prelude Require Import mapset. From iris.prelude Require Import mapset countable.
From iris.prelude Require Export fin_maps. From iris.prelude Require Export fin_maps.
Local Open Scope positive_scope. Local Open Scope positive_scope.
...@@ -300,11 +300,19 @@ Proof. ...@@ -300,11 +300,19 @@ Proof.
- intros ??? ?? [??] [??] ?. by apply Pmerge_lookup. - intros ??? ?? [??] [??] ?. by apply Pmerge_lookup.
Qed. Qed.
Program Instance Pmap_countable `{Countable A} : Countable (Pmap A) := {
encode m := encode (map_to_list m : list (positive * A));
decode p := map_of_list <$> decode p
}.
Next Obligation.
intros A ?? m; simpl. rewrite decode_encode; simpl. by rewrite map_of_to_list.
Qed.
(** * Finite sets *) (** * Finite sets *)
(** We construct sets of [positives]s satisfying extensional equality. *) (** We construct sets of [positives]s satisfying extensional equality. *)
Notation Pset := (mapset Pmap). Notation Pset := (mapset Pmap).
Instance Pmap_dom {A} : Dom (Pmap A) Pset := mapset_dom. Instance Pmap_dom {A} : Dom (Pmap A) Pset := mapset_dom.
Instance: FinMapDom positive Pmap Pset := mapset_dom_spec. Instance Pmap_dom_spec : FinMapDom positive Pmap Pset := mapset_dom_spec.
(** * Fresh numbers *) (** * Fresh numbers *)
Fixpoint Pdepth {A} (m : Pmap_raw A) : nat := Fixpoint Pdepth {A} (m : Pmap_raw A) : nat :=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment