-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- In light of a recent issue with `--overlapping-instances` (c.f. agda/agda#6895), I removed all uses of overlapping in the codebase, which we actually redundant. - `Foreign.Convertible` no longer relying on `Coercible`. - `Axiom.Set.List` now exports general decidable equality to avoid ambiguity when `Interface.DecEq.DecEq⇒Dec` is also in scope.
- Loading branch information
1 parent
f3011bb
commit 71b9eae
Showing
6 changed files
with
55 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,64 @@ | ||
{-# OPTIONS --overlapping-instances #-} | ||
module Foreign.Convertible where | ||
|
||
open import Ledger.Prelude hiding (map) | ||
|
||
open import Data.List using (map) | ||
|
||
open import Foreign.Haskell | ||
open import Foreign.Haskell.Coerce | ||
open import Ledger.Prelude | ||
|
||
record Convertible (A B : Set) : Set where | ||
field to : A → B | ||
from : B → A | ||
|
||
open Convertible ⦃...⦄ public | ||
|
||
private variable A B A' B' K K' V V' : Set | ||
private variable | ||
A B A' B' K K' V V' : Set | ||
P Q : Set → Set | ||
|
||
Convertible₁ : (Set → Set) → (Set → Set) → Set₁ | ||
Convertible₁ T U = ∀ {A B} → ⦃ Convertible A B ⦄ → Convertible (T A) (U B) | ||
|
||
Convertible₂ : (Set → Set → Set) → (Set → Set → Set) → Set₁ | ||
Convertible₂ T U = ∀ {A B} → ⦃ Convertible A B ⦄ → Convertible₁ (T A) (U B) | ||
|
||
Convertible-Refl : Convertible A A | ||
Convertible-Refl = λ where | ||
.to → id | ||
.from → id | ||
|
||
-- ** instances | ||
|
||
Bifunctor⇒Convertible : ∀ {F : Set → Set → Set} → ⦃ Bifunctor F ⦄ | ||
→ ⦃ Convertible A A' ⦄ → ⦃ Convertible B B' ⦄ | ||
→ Convertible (F A B) (F A' B') | ||
Bifunctor⇒Convertible ⦃ _ ⦄ ⦃ ca ⦄ ⦃ cb ⦄ = λ where | ||
.to → bimap (to ⦃ ca ⦄) (to ⦃ cb ⦄) | ||
.from → bimap (from ⦃ ca ⦄) (from ⦃ cb ⦄) | ||
|
||
open import Foreign.Haskell | ||
|
||
instance | ||
Coercible⇒Convertible : ⦃ Coercible A B ⦄ → Convertible A B | ||
Coercible⇒Convertible = λ where | ||
.to → coerce | ||
.from → coerce ⦃ TrustMe ⦄ -- coercibility is symmetric, I promise | ||
Convertible-× : Convertible₂ _×_ _×_ | ||
Convertible-× = Bifunctor⇒Convertible | ||
|
||
Convertible-Pair : ⦃ Convertible A A' ⦄ → ⦃ Convertible B B' ⦄ | ||
→ Convertible (A × B) (Pair A' B') | ||
Convertible-Pair : Convertible₂ _×_ Pair | ||
Convertible-Pair = λ where | ||
.to (a , b) → to a , to b | ||
.to (a , b) → to a , to b | ||
.from (a , b) → from a , from b | ||
|
||
Convertible-FinSet : ⦃ Convertible A A' ⦄ → Convertible (ℙ A) (List A') | ||
Convertible-⊎ : Convertible₂ _⊎_ _⊎_ | ||
Convertible-⊎ = Bifunctor⇒Convertible | ||
|
||
Convertible-Either : Convertible₂ _⊎_ Either | ||
Convertible-Either = λ where | ||
.to (inj₁ a) → left (to a) | ||
.to (inj₂ b) → right (to b) | ||
.from (left a) → inj₁ (from a) | ||
.from (right b) → inj₂ (from b) | ||
|
||
Convertible-FinSet : Convertible₁ ℙ_ List | ||
Convertible-FinSet = λ where | ||
.to s → map to (setToList s) | ||
.from l → fromList (map from l) | ||
|
||
Convertible-Map : ⦃ DecEq K ⦄ → ⦃ Convertible K K' ⦄ → ⦃ Convertible V V' ⦄ | ||
→ Convertible (K ⇀ V) (List $ Pair K' V') | ||
→ Convertible (K ⇀ V) (List $ Pair K' V') | ||
Convertible-Map = λ where | ||
.to m → to (proj₁ m) | ||
.from m → fromListᵐ (map from m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters