问题
Is it possible to declare fields in a record irrelevant but still use them somewhere?
Suppose I have
postulate f : ℕ → ℕ
record Silly x : Set where
field
n : ℕ
s : f n ≡ x
open Silly
Then, I can
same-silly : ∀{x} {p q : Silly x} → f (n p) ≡ f(n q)
same-silly {x} {p} {q} = ≡-trans (s p) (≡-sym (s q))
But if I use dotted-fields,
record Silly x : Set where
field
n : ℕ
.s : f n ≡ x -- note the dot
then same-silly
can no longer be proven ---not by me at least.
When I attempt to use s
, as in the definition above, Agda informs me Identifier s is declared irrelevant, so it cannot be used here
.
I understand that I declared s
irrelevant by dotting it, but I still want a bit of access to it: enough access to define same-silly
. Is there a way to have this little bit but not complete access? What I mean is that I am thinking of s
as a coherency condition that I'd like to use once in a blue-moon, but not terrible important and so the dot. Maybe ignore this paragraph.
Is it possible to form same-silly
and have s
be dotted?
(
Aside: does the dotted pattern mean propositional equality coincides with the relation
_~_ : ∀{x} (p q : Silly x) → Set
p ~ q = n p ≡ n q
? In particular, by adding to the record constructor _#_
, I can show
eq : ∀{m x}{p q : f m ≡ x} → (m # p) ≡ (m # q)
eq = ≡-refl
but I'm not yet certain that dotting fields means that definitionally equality ignores the dotted fields.
I'm browsing http://wiki.portal.chalmers.se/agda/agda.php?n=ForkedReferenceManual.Records#Irrelevantfields; which says that there are projections for dotted fields, but it seems I cannot use them anywhere.
)
Any help is appreciated!
回答1:
You can use irrelevant projections, but only when you are working in an irrelevant context. One way to enter an irrelevant context is to make the proof itself irrelevant:
.same-silly : ∀{x} {p q : Silly x} → f (n p) ≡ f(n q)
same-silly {x} {p} {q} = ≡-trans (s p) (≡-sym (s q))
This means that you will only be able to use the same-silly proof in irrelevant contexts as well.
Regarding your second question, the answer is yes: you can prove the following:
silly-equality : ∀ {n} {x y : Silly n} → x ~ y → x ≡ y
silly-equality refl = refl
So equality of the first projection (your ~ relation) really corresponds to propositional equality.
来源:https://stackoverflow.com/questions/34585992/using-irrelevant-fields