-
Notifications
You must be signed in to change notification settings - Fork 21
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
Generalized coercions #420
Open
Tragicus
wants to merge
2
commits into
math-comp:master
Choose a base branch
from
Tragicus:proto-coercion
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From Coq Require Import ssreflect. | ||
From HB Require Import structures. | ||
|
||
HB.mixin Record isSigma (T : Type) (P : T -> Prop) (x : T) := { | ||
_ : P x | ||
}. | ||
|
||
#[short(type="sigType"), typeclass] | ||
HB.structure Definition Sig (T : Type) (P : T -> Prop) := {x of isSigma T P x}. | ||
|
||
Section Sigma. | ||
|
||
Check fun (T : Type) (P : T -> Prop) (x : sigType T P) => x : T. | ||
Check fun (T : Type) (P : T -> Prop) (x : T) (Px : Sig T P x) => x : sigType T P. | ||
Fail Check fun (T : Type) (P : T -> Prop) (x : T) => x : sigType T P. | ||
|
||
Axioms (A B B' C : Type) (AtoB : A -> B) (BtoB' : B -> B'). | ||
Axioms (P : A -> Prop) (CtoAP : C -> sigType A P). | ||
Coercion AtoB : A >-> B. | ||
Coercion BtoB' : B >-> B'. | ||
(* does postcompose automatically with Coq coercions*) | ||
Check fun (x : sigType A P) => x : B. | ||
Check fun (x : sigType A P) => x : B'. | ||
|
||
(* testing a Coq coercion to sigType *) | ||
Coercion CtoAP : C >-> sigType. | ||
Check fun (x : C) => x : sigType A P. | ||
|
||
(* does not precompose automatically with Coq coercions *) | ||
Fail Check fun (x : C) => x : A. | ||
Check fun (x : C) => (x : sigType A P) : A. | ||
Check fun (x : C) => (x : sigType A P) : B. | ||
|
||
Axioms (x : A) (Px : Sig A P x). | ||
|
||
(* should not work indeed *) | ||
Fail Check (x : sigType A P). | ||
|
||
(* this works though ...*) | ||
Succeed Check (let Px' := Px in x : sigType A P). | ||
|
||
HB.instance Definition _ := Px. | ||
Fail Check x : sigType A P. | ||
|
||
End Sigma. | ||
|
||
HB.mixin Record isSigmaT (P : Type -> Prop) (x : Type) := { _ : P x }. | ||
#[short(type="sigTType"), typeclass] | ||
HB.structure Definition SigT (P : Type -> Prop) := {x of isSigmaT P x}. | ||
|
||
Section SigmaT. | ||
|
||
Axioms (X : Type) (PT : Type -> Prop) (PX : SigT PT X). | ||
|
||
(* should not work indeed *) | ||
Fail Check (X : sigTType PT). | ||
|
||
(* this works though now ... cf my next point*) | ||
Succeed Check (let PX' := PX in X : sigTType PT). | ||
|
||
(* Now this works *) | ||
HB.instance Definition _ := PX. | ||
Succeed Check X : sigTType PT. | ||
|
||
End SigmaT. |
Oops, something went wrong.
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 looks really nice! But...
(x : T)
has been endowed with aHB.instance
ofisSigma
. e.g.In comparison, the analogous code, but on
Type
works: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.
I think the code just above does not work because the whole business does not kick in since the coercion
sort
is handled by Coq (the tgt is a supported one in this case), so nobody triggers the TC search.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.
I am extremely confused as to why it works in
Type
but not inProp
. In both cases,HB.instance
declares canonical structures and not typeclasses, so it should not work.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.
Your tests with a
let
work and not the previous ones because (afaict) the elaborator sees the local context but not the global context.