Use instances to simplify printing code

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2024-03-11 12:50:05 -07:00
parent 56da61b339
commit 040c13caba
5 changed files with 78 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ open import Data.Empty using (⊥-elim)
open import Data.Product using (_,_)
open import Data.Nat using (_≤_; ; z≤n; s≤s; suc)
open import Function using (_∘_)
open import Showable using (Showable; show)
open import Relation.Binary.PropositionalEquality as Eq
using (_≡_; sym; subst; refl)
@@ -24,6 +25,16 @@ data AboveBelow : Set a where
: AboveBelow
[_] : A AboveBelow
instance
showable : {{ showableA : Showable A }} Showable AboveBelow
showable = record
{ show = (λ
{ ""
; ""
; [ a ] show a
})
}
data _≈_ : AboveBelow AboveBelow Set a where
≈-⊥-⊥ :
≈-- :

View File

@@ -45,11 +45,17 @@ open import Function using (_∘_)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Utils using (Pairwise; _∷_; [])
open import Data.Empty using (⊥-elim)
open import Showable using (Showable; show)
module WithKeys (ks : List A) where
FiniteMap : Set (a ⊔ℓ b)
FiniteMap = Σ Map (λ m Map.keys m ks)
instance
showable : {{ showableA : Showable A }} {{ showableB : Showable B }}
Showable FiniteMap
showable = record { show = λ (m₁ , _) show m₁ }
_≈_ : FiniteMap FiniteMap Set (a ⊔ℓ b)
_≈_ (m₁ , _) (m₂ , _) = m₁ ≈ᵐ m₂

View File

@@ -13,13 +13,15 @@ open import Data.List.Membership.Propositional as MemProp using () renaming (_
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Nat using ()
open import Data.List using (List; map; []; _∷_; _++_)
open import Data.List using (List; map; []; _∷_; _++_) renaming (foldr to foldrˡ)
open import Data.List.Relation.Unary.All using (All; []; _∷_)
open import Data.List.Relation.Unary.Any using (Any; here; there) -- TODO: re-export these with nicer names from map
open import Data.Product using (_×_; _,_; Σ; proj₁ ; proj₂)
open import Data.Empty using (⊥; ⊥-elim)
open import Equivalence
open import Utils using (Unique; push; Unique-append; All¬-¬Any; All-x∈xs)
open import Data.String using () renaming (_++_ to _++ˢ_)
open import Showable using (Showable; show)
open IsLattice lB using () renaming
( ≈-refl to ≈₂-refl; ≈-sym to ≈₂-sym; ≈-trans to ≈₂-trans
@@ -478,6 +480,14 @@ private module ImplInsert (f : B → B → B) where
Map : Set (a ⊔ℓ b)
Map = Σ (List (A × B)) (λ l Unique (ImplKeys.keys l))
instance
showable : {{ showableA : Showable A }} {{ showableB : Showable B }}
Showable Map
showable = record
{ show = λ (kvs , _)
"{" ++ˢ foldrˡ (λ (x , y) rest show x ++ˢ "" ++ˢ show y ++ˢ ", " ++ˢ rest) "" kvs ++ˢ "}"
}
empty : Map
empty = ([] , Utils.empty)