diff options
author | Helmut Grohne <grohne@cs.uni-bonn.de> | 2014-01-30 14:01:10 +0100 |
---|---|---|
committer | Helmut Grohne <grohne@cs.uni-bonn.de> | 2014-01-30 14:01:10 +0100 |
commit | 934f2003d4f47c2af3a91cd827d75caeded7ec7a (patch) | |
tree | 903a3a699f6f64da08a60a1f54dc345057214779 | |
parent | 1c3da162d500cfe885fa21b4d75847c4bcbb2aa1 (diff) | |
download | bidiragda-934f2003d4f47c2af3a91cd827d75caeded7ec7a.tar.gz |
express VecBFF via PartialVecBFF
-rw-r--r-- | BFF.agda | 28 | ||||
-rw-r--r-- | FreeTheorems.agda | 5 | ||||
-rw-r--r-- | Generic.agda | 10 |
3 files changed, 20 insertions, 23 deletions
@@ -12,18 +12,18 @@ open import Data.List using (List ; [] ; _∷_ ; map ; length) open import Data.Vec using (Vec ; toList ; fromList ; tabulate ; allFin) renaming (lookup to lookupV ; map to mapV ; [] to []V ; _∷_ to _∷V_) open import Function using (id ; _∘_ ; flip) open import Function.Equality using (_⟶_ ; _⟨$⟩_) -open import Function.Injection using (module Injection) renaming (Injection to _↪_) +open import Function.Injection using (module Injection) renaming (Injection to _↪_ ; id to id↪) open import Relation.Binary using (Setoid ; DecSetoid ; module DecSetoid) -open import Relation.Binary.PropositionalEquality using () renaming (setoid to EqSetoid) +open import Relation.Binary.PropositionalEquality using (cong) renaming (setoid to EqSetoid) open Injection using (to) open import FinMap -open import Generic using (mapMV) +open import Generic using (mapMV ; ≡-to-Π) import CheckInsert import FreeTheorems -module VecBFF (A : DecSetoid ℓ₀ ℓ₀) where - open FreeTheorems.VecVec public using (get-type) +module PartialVecBFF (A : DecSetoid ℓ₀ ℓ₀) where + open FreeTheorems.PartialVecVec public using (get-type) open module A = DecSetoid A using (Carrier) renaming (_≟_ to deq) open CheckInsert A @@ -37,7 +37,7 @@ module VecBFF (A : DecSetoid ℓ₀ ℓ₀) where denumerate : {n : ℕ} → Vec Carrier n → Fin n → Carrier denumerate = flip lookupV - bff : {getlen : ℕ → ℕ} → (get-type getlen) → ({n : ℕ} → Vec Carrier n → Vec Carrier (getlen n) → Maybe (Vec Carrier n)) + bff : {I : Setoid ℓ₀ ℓ₀} {gl₁ : I ↪ (EqSetoid ℕ)} {gl₂ : I ⟶ EqSetoid ℕ} → get-type gl₁ gl₂ → ({i : Setoid.Carrier I} → Vec Carrier (to gl₁ ⟨$⟩ i) → Vec Carrier (gl₂ ⟨$⟩ i) → Maybe (Vec Carrier (to gl₁ ⟨$⟩ i))) bff get s v = let s′ = enumerate s t′ = get s′ g = fromFunc (denumerate s) @@ -46,18 +46,12 @@ module VecBFF (A : DecSetoid ℓ₀ ℓ₀) where h′ = (flip union g′) <$> h in h′ >>= flip mapMV s′ ∘ flip lookupV -module PartialVecBFF (A : DecSetoid ℓ₀ ℓ₀) where - open FreeTheorems.PartialVecVec public using (get-type) +module VecBFF (A : DecSetoid ℓ₀ ℓ₀) where + open FreeTheorems.VecVec public using (get-type) open module A = DecSetoid A using (Carrier) renaming (_≟_ to deq) open CheckInsert A - open VecBFF A public using (assoc ; enumerate ; denumerate) + open PartialVecBFF A public using (assoc ; enumerate ; denumerate) - bff : {I : Setoid ℓ₀ ℓ₀} {gl₁ : I ↪ (EqSetoid ℕ)} {gl₂ : I ⟶ EqSetoid ℕ} → get-type gl₁ gl₂ → ({i : Setoid.Carrier I} → Vec Carrier (to gl₁ ⟨$⟩ i) → Vec Carrier (gl₂ ⟨$⟩ i) → Maybe (Vec Carrier (to gl₁ ⟨$⟩ i))) - bff get s v = let s′ = enumerate s - t′ = get s′ - g = fromFunc (denumerate s) - g′ = delete-many t′ g - h = assoc t′ v - h′ = (flip union g′) <$> h - in h′ >>= flip mapMV s′ ∘ flip lookupV + bff : {getlen : ℕ → ℕ} → (get-type getlen) → ({n : ℕ} → Vec Carrier n → Vec Carrier (getlen n) → Maybe (Vec Carrier n)) + bff {getlen} get s v = PartialVecBFF.bff A {_} {id↪} {≡-to-Π getlen} get {_} s v diff --git a/FreeTheorems.agda b/FreeTheorems.agda index aacb95a..c22a68d 100644 --- a/FreeTheorems.agda +++ b/FreeTheorems.agda @@ -11,6 +11,8 @@ open import Relation.Binary.PropositionalEquality using (_≗_ ; cong) renaming open import Relation.Binary using (Setoid) open Injection using (to) +open import Generic using (≡-to-Π) + module ListList where get-type : Set₁ get-type = {A : Set} → List A → List A @@ -37,8 +39,5 @@ module PartialVecVec where open VecVec using () renaming (free-theorem-type to VecVec-free-theorem-type) - ≡-to-Π : {A B : Set} → (A → B) → EqSetoid A ⟶ EqSetoid B - ≡-to-Π f = record { _⟨$⟩_ = f; cong = cong f } - VecVec-free-theorem : VecVec-free-theorem-type VecVec-free-theorem {getlen} get = free-theorem Function.Injection.id (≡-to-Π getlen) get diff --git a/Generic.agda b/Generic.agda index 81292ff..a734ec2 100644 --- a/Generic.agda +++ b/Generic.agda @@ -9,16 +9,20 @@ open import Data.Product using (_×_ ; _,_) open import Data.Vec using (Vec ; toList ; fromList ; map) renaming ([] to []V ; _∷_ to _∷V_) open import Data.Vec.Equality using () renaming (module Equality to VecEq) open import Function using (_∘_ ; id) +open import Function.Equality using (_⟶_) open import Level using () renaming (zero to ℓ₀) open import Relation.Binary using (Setoid ; module Setoid) open import Relation.Binary.Core using (_≡_ ; refl) open import Relation.Binary.Indexed using (_at_) renaming (Setoid to ISetoid) -open import Relation.Binary.PropositionalEquality using (_≗_ ; cong ; subst ; trans) renaming (setoid to PropEq) +open import Relation.Binary.PropositionalEquality using (_≗_ ; cong ; subst ; trans) renaming (setoid to EqSetoid) open Setoid using () renaming (_≈_ to _∋_≈_) open Category.Functor.RawFunctor {Level.zero} Data.Maybe.functor using (_<$>_) open Category.Monad.RawMonad {Level.zero} Data.Maybe.monad using (_>>=_) +≡-to-Π : {A B : Set} → (A → B) → EqSetoid A ⟶ EqSetoid B +≡-to-Π f = record { _⟨$⟩_ = f; cong = cong f } + just-injective : {A : Set} → {x y : A} → Maybe.just x ≡ Maybe.just y → x ≡ y just-injective refl = refl @@ -40,11 +44,11 @@ mapMV-purity : {A B : Set} {n : ℕ} → (f : A → B) → (v : Vec A n) → map mapMV-purity f []V = refl mapMV-purity f (x ∷V xs) rewrite mapMV-purity f xs = refl -maybeEq-from-≡ : {A : Set} {a b : Maybe A} → a ≡ b → MaybeEq (PropEq A) ∋ a ≈ b +maybeEq-from-≡ : {A : Set} {a b : Maybe A} → a ≡ b → MaybeEq (EqSetoid A) ∋ a ≈ b maybeEq-from-≡ {a = just x} {b = .(just x)} refl = just refl maybeEq-from-≡ {a = nothing} {b = .nothing} refl = nothing -maybeEq-to-≡ : {A : Set} {a b : Maybe A} → MaybeEq (PropEq A) ∋ a ≈ b → a ≡ b +maybeEq-to-≡ : {A : Set} {a b : Maybe A} → MaybeEq (EqSetoid A) ∋ a ≈ b → a ≡ b maybeEq-to-≡ (just refl) = refl maybeEq-to-≡ nothing = refl |