@@ -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
317327toCoreDefn (I. ConstructorDefn cs) ty =
0 commit comments