The element at a position, as an option: an index past the end is absent,
never an error and never a wrong element.
317def stdListIndex =
318 (lambda erased element : Type 0 .
319 unrestricted values : (family StdList element) .
320 unrestricted position : Nat .
321 app
322 (eliminate
323 StdList
324 (lambda unrestricted current : (family StdList element) . pi unrestricted remaining : Nat .
325 family StdOption element)
326 values
327 (branch
328 StdListEmpty
329 .
330 lambda
331 unrestricted
332 remaining
333 :
334 Nat
335 .
336 constructor StdOption StdNone element)
337 (branch
338 StdListCons
339 head
340 tail
341 induction
342 .
343 lambda
344 unrestricted
345 remaining
346 :
347 Nat
348 .
349 nat-eliminate
350 (lambda unrestricted current : Nat . family StdOption element)
351 (constructor StdOption StdSome element head)
352 (lambda unrestricted predecessor : Nat .
353 unrestricted inner : (family StdOption element) .
354 induction (nat-subtract remaining 1))
355 -- a branch on zero, not a recursion on `remaining`: a
356 -- strict evaluator would evaluate every smaller position's
357 -- lookup, doubling the cost with each position
358 (nat-less-than 0 remaining)))
359 position)The compiler supplied declaration spans and resolved links from this source snapshot. This page does not assert that this file belongs to a checked closure.