Skip to content

Commit df5feac

Browse files
committed
record projection examples
1 parent 07886db commit df5feac

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

app/Agda/Core/ToCore.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Agda.TypeChecking.Pretty (PrettyTCM(prettyTCM))
5252

5353
import Agda.Syntax.Common.Pretty(text, render)
5454

55+
import Agda.Core.UtilsH(traceMagenta)
5556

5657
-- TODO(flupe): move this to Agda.Core.Syntax
5758
-- | Apply a core term to elims
@@ -409,8 +410,12 @@ instance ToCore I.Elim where
409410
toCore (I.Apply x) = toCore x
410411
--TODO (diode-lang) : Support projection as an Elim
411412
-- toCore (I.Proj _ qn) = TDef <$> lookupDefOrData qn
412-
toCore (I.Proj _ qn) = throwError "TODO: Support record projections"
413-
toCore I.IApply{} = throwError "cubical endpoint application not supported"
413+
toCore (I.Proj _ qn) = do
414+
let m_idx = traceMagenta ("qn: " ++ show (pretty qn)) $ lookupDef qn >>= \case
415+
Nothing -> throwError $ "[When translating an Elim] Trying to access an unknown definition: " <+> pretty qn
416+
Just ident -> pure ident
417+
TDef <$> m_idx
418+
toCore I.IApply{} = throwError "[When translating an Elim] cubical endpoint application not supported"
414419

415420

416421
instance ToCore a => ToCore [a] where

test/EtaRecords.agda

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
module EtaRecords where
2-
3-
data : Set where
4-
--no constructor
5-
2+
63
data Nat : Set where
74
Zero : Nat
85
Suc : Nat Nat
@@ -51,23 +48,19 @@ x' = Pair.constructor Zero (Suc Zero)
5148
proj_example : Nat
5249
proj_example = Pair.fst x
5350

54-
-- y : Pair Nat Bool
55-
-- y = record { fst = Pair.fst x; snd = False }
56-
57-
-- z : PairExplCon Nat Nat
58-
-- z = _,_ Zero (Suc Zero)
51+
y : Pair Nat Bool
52+
y = record { fst = Pair.fst x; snd = False }
5953

60-
-- eta-R-two : (A B : Set) (x : Pair A B) →
61-
-- x ≡ record { fst = (const (Pair A B → A) Pair.fst Pair.fst) x ; snd = Pair.snd x }
62-
-- eta-R-two = λ A B → λ x → refl
54+
z : PairExplCon Nat Nat
55+
z = _,_ Zero (Suc Zero)
6356

64-
-- eta-R-two-expl-con : (A B : Set) (x : PairExplCon A B) →
65-
-- x ≡ (_,_ (const (PairExplCon A B → A) PairExplCon.fstE PairExplCon.fstE x) (PairExplCon.sndE x))
66-
-- eta-R-two-expl-con = λ A B → λ x → refl
57+
eta-R-two : (A B : Set) (x : Pair A B)
58+
x ≡ record { fst = (const (Pair A B A) Pair.fst Pair.fst) x ; snd = Pair.snd x }
59+
eta-R-two = λ A B λ x refl
6760

68-
-- eta-R-two : (A B : Set) (x : Pair A B) →
69-
-- x ≡ record { fst = (const (Pair A B → A) Pair.fst Pair.fst) x ; snd = Pair.snd x }
70-
-- eta-R-two = λ A B → λ x → {!!}
61+
eta-R-two-expl-con : (A B : Set) (x : PairExplCon A B)
62+
x ≡ (_,_ (const (PairExplCon A B A) PairExplCon.fstE PairExplCon.fstE x) (PairExplCon.sndE x))
63+
eta-R-two-expl-con = λ A B λ x refl
7164

7265
-- (diode-lang): I don't think this statement is actually provable, because we have turned off eta-equality
7366
-- eta-R-two_expl : (A B : Set) (x : PairNoEta A B) →

test/RecordProjection.agda

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
data Nat : Set where
3+
Zero : Nat
4+
Suc : Nat Nat
5+
6+
data Bool : Set where
7+
True : Bool
8+
False : Bool
9+
10+
data _≡_ {A : Set} (x : A) : A Set where
11+
refl : x ≡ x
12+
13+
const : (A : Set) A A A
14+
const = λ A λ x λ y x
15+
16+
record Pair (A B : Set) : Set where
17+
field
18+
fst : A
19+
snd : B
20+
21+
x : Pair Nat Nat
22+
x = record { fst = Zero; snd = Suc Zero }
23+
24+
proj_example1 : Nat
25+
proj_example1 = Pair.fst x
26+
27+
proj_example2 : Bool
28+
proj_example2 = (record { fst = Zero; snd = False }) .Pair.snd
29+
30+
proj_example3 : Bool
31+
proj_example3 = (const (Pair Nat Bool) (record { fst = Zero; snd = False }) (record { fst = Zero; snd = False })) .Pair.snd
32+
33+

0 commit comments

Comments
 (0)