Skip to content

'Gradual' decidable equality combinators #803

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

Closed
gallais opened this issue Jun 4, 2019 · 5 comments
Closed

'Gradual' decidable equality combinators #803

gallais opened this issue Jun 4, 2019 · 5 comments

Comments

@gallais
Copy link
Member

gallais commented Jun 4, 2019

When you define decidable equality for e.g.

data Rose (A : Set) : Set where
  node : List (Rose A)  Rose A

you can't reuse Data.List.Properties' ≡-dec because it makes the
termination checker scream. However you would not have to redo all the
work if only we provided

∷-dec : Dec (x ≡ y)  Dec (xs ≡ ys)  Dec (x ∷ xs ≡ y ∷ ys)
∷-dec x≟y xs≟ys = map′ (uncurry (cong₂ _∷_)) ∷-injective (x≟y ×-dec xs≟ys)

Indeed mutually defining

_≟_  : Decidable {A = Rose A} _≡_
_≟s_ : Decidable {A = List (Rose A)} _≡_

then becomes easy:

node xs ≟ node ys = map′ (cong node) node-injective (xs ≟s ys)

[]       ≟s []       = yes refl
(x ∷ xs) ≟s (y ∷ ys) = ∷-dec (x ≟ y) (xs ≟s ys)

[] ≟s (x ∷ ys) = no (λ ())
(x ∷ xs) ≟s [] = no (λ ())

I have used this trick twice in #799 to simplify decidable equality proofs
involving Arg and Abs and there are probably numerous other places where
we can define these combinators in the stdlib.

Edit: self-contained gist

MatthewDaggitt pushed a commit that referenced this issue Jun 15, 2019
* [ float ] bringing in the new agda features

* [ name ] with safe decidable equality

* [ meta ] with safe decidable equality

* [ reflection ] safe and compatible with --without-K

* [ literal ] moved to their own file

* [ reflection ] more deprecations

* [ cleanup ] import list of Reflection

* [ reflection ] extracting Argument, Pattern

Also cleanup, deprecation, new unArg-dec magic.

* [ fix ] removing Reflection from the list of unsafe modules

* [ changelog ] list new modules

* [ deprecation ] of arg-info injectivity proofs

* [ abstraction ] taken to its own module

* [ build ] removing fake unsafe files, cleaning up GenerateEverything

* [ refactor ] introducing DecidableEquality

* [ re #803 ] 'gradual' decidable equality combinator for list

* [ reflection ] putting Term in its own module

Some cleaning up still needed. However I am stuck on a refactoring.

* [ fix ] forgot to add Reflection.Term

+ Additional cleanup

* [ fix ] no need to deprecate *private* definitions!

* [ deprecated ] functions moved to Reflection.Term

* [ reflection ] moving Definition to Reflection.Definition

* [ typo ]

* [ cosmetic ] more uses of DecidableEquality

* [ changelog ] new modules
@jamesmckinna
Copy link
Contributor

Towards a general solution to deriving (Eq)-style automated support?
(I'm told that this is a frequently-solved problem among commercial Agda developers)

@JacquesCarette
Copy link
Contributor

'commercial Agda developers' ???

@jamesmckinna
Copy link
Contributor

Was this issue effectively put to bed by #811 ? If so, we should close, but perhaps document the pattern in the library design/style guide documentation?

@JacquesCarette
Copy link
Contributor

Agreed. Can we even test its use internally, or would that introduce dependencies that are a bit over the top?

@jamesmckinna
Copy link
Contributor

Stub content added to doc/style-guide.md in #2270, so closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants