-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add properties of Data.Refinement
and refactor module structure
#2492
Merged
JacquesCarette
merged 6 commits into
agda:master
from
jamesmckinna:refinement-value-injective
Nov 2, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
09ee866
injectivity of `value`
jamesmckinna baf6c82
tighten `import`s
jamesmckinna 36cd876
refactor: abstract out `variable`s
jamesmckinna 65d9eac
added `DecidableEquality`
jamesmckinna 0b8f459
refactor into `Base`, `Properties` with re-export from `Refinement`
jamesmckinna e09f796
Merge branch 'master' into refinement-value-injective
jamesmckinna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Refinement type: a value together with a proof irrelevant witness. | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Data.Refinement.Base where | ||
|
||
open import Level | ||
open import Data.Irrelevant as Irrelevant using (Irrelevant) | ||
open import Function.Base | ||
open import Relation.Unary using (IUniversal; _⇒_; _⊢_) | ||
|
||
private | ||
variable | ||
a b p q : Level | ||
A : Set a | ||
B : Set b | ||
P : A → Set p | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- Definition | ||
|
||
record Refinement (A : Set a) (P : A → Set p) : Set (a ⊔ p) where | ||
constructor _,_ | ||
field value : A | ||
proof : Irrelevant (P value) | ||
infixr 4 _,_ | ||
open Refinement public | ||
|
||
-- The syntax declaration below is meant to mimic set comprehension. | ||
-- It is attached to Refinement-syntax, to make it easy to import | ||
-- Data.Refinement without the special syntax. | ||
|
||
infix 2 Refinement-syntax | ||
Refinement-syntax = Refinement | ||
syntax Refinement-syntax A (λ x → P) = [ x ∈ A ∣ P ] | ||
|
||
------------------------------------------------------------------------ | ||
-- Basic operations | ||
|
||
module _ {Q : B → Set q} where | ||
|
||
map : (f : A → B) → ∀[ P ⇒ f ⊢ Q ] → | ||
[ a ∈ A ∣ P a ] → [ b ∈ B ∣ Q b ] | ||
map f prf (a , p) = f a , Irrelevant.map prf p | ||
|
||
module _ {Q : A → Set q} where | ||
|
||
refine : ∀[ P ⇒ Q ] → [ a ∈ A ∣ P a ] → [ a ∈ A ∣ Q a ] | ||
refine = map id |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
------------------------------------------------------------------------ | ||
-- The Agda standard library | ||
-- | ||
-- Properties of refinement types | ||
------------------------------------------------------------------------ | ||
|
||
{-# OPTIONS --cubical-compatible --safe #-} | ||
|
||
module Data.Refinement.Properties where | ||
|
||
open import Level | ||
open import Data.Refinement.Base | ||
open import Relation.Binary.Definitions using (DecidableEquality) | ||
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) | ||
import Relation.Nullary.Decidable.Core as Dec | ||
|
||
private | ||
variable | ||
a p : Level | ||
A : Set a | ||
P : A → Set p | ||
v w : [ x ∈ A ∣ P x ] | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- Basic properties | ||
|
||
value-injective : value v ≡ value w → v ≡ w | ||
value-injective refl = refl | ||
|
||
module _ (eq? : DecidableEquality A) where | ||
|
||
infix 4 _≟_ | ||
_≟_ : DecidableEquality [ x ∈ A ∣ P x ] | ||
v ≟ w = Dec.map′ value-injective (cong value) (eq? (value v) (value w)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clearly a pattern, which currently is reified only under
Relation.Decidable.Nullary.Decidable.via-injection
, but it seems excessive to create anInjection
bundle solely for the sake of applying the lemma, so suggest some downstream refactoring to make this a property ofInjective
(bare) functions?