Skip to content

Commit 3d57699

Browse files
committed
Parameters lists and index lists are getting correctly translated
1 parent cbb70cc commit 3d57699

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

app/Agda/Core/ToCore.hs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,38 @@ instance ToCore I.Term where
148148

149149
-- TODO(flupe): add literals once they're added to core
150150
toCore (I.Lit l) = throwError "literals not supported"
151-
152-
toCore (I.Def qn es)
151+
152+
toCore (I.Def qn es)
153153
| Just args <- allApplyElims es
154154
= do
155155
-- Try looking up as definition first
156156
catchError
157-
(do
157+
(do
158158
idx <- lookupDef qn
159159
let def = TDef idx
160160
coreEs <- toCore es
161161
return (tApp def coreEs)
162162
)
163163
--Otherwise, try looking up as datatype
164-
(\_ -> do
164+
(\_ -> do
165165
(idx, (amountOfParams, amountOfIndices)) <- lookupData qn
166166

167167
--always take all parameters
168168
paramTermS <- toTermS <$> toCore (take amountOfParams args)
169+
170+
-- @m@ is the amount of arguments to the index list which are missing
171+
let indexListGiven = drop amountOfParams args
172+
let m = amountOfIndices - (length indexListGiven)
173+
174+
-- Construct @m@ additional deBruijn indices
175+
-- so we get [TVar 2, TVar 1, TVar 0, ...] of length m
176+
let additionalVars = reverse $ take m $ TVar <$> iterate Scope.inThere Scope.inHere
169177

170-
indexTermS <- toTermS <$> toCore (drop amountOfParams args)
178+
indexTermS <- toTermS . (++ additionalVars) <$> toCore (raise m indexListGiven)
179+
let tdata = TData idx paramTermS indexTermS
171180

172-
return (TData idx paramTermS indexTermS)
181+
-- in the end, we have (TLam (TLam (TLam ...))) of depth m
182+
return (iterate TLam tdata !! m)
173183
)
174184

175185
toCore I.Def{} = throwError "cubical endpoint application to definitions/datatypes not supported"
@@ -311,7 +321,7 @@ toCoreDefn (I.RecordDefn rd) ty =
311321
withError (\e -> multiLineText $ "record definition failure \n" <> Pretty.render (nest 1 e)) $ do
312322
let I.RecordData{
313323
_recPars = pars,
314-
_recFields = fields} = rd
324+
_recFields = fields} = rd
315325
throwError "records are not supported"
316326

317327
toCoreDefn (I.ConstructorDefn cs) ty =

test/EtaFunctions.agda

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ addTwoAfterAddOne = λ x → (comp Nat Nat Nat addTwo addOne x)
3030
eta-higher : (A B C : Set) (f : A B C) (λ x λ y f x y) ≡ f
3131
eta-higher = λ A B C λ f refl
3232

33-
3433
eta-counterexample-simple : addOne ≡ (λ x (suc (const x x)))
3534
eta-counterexample-simple = refl
3635

0 commit comments

Comments
 (0)