Skip to content

Instantly share code, notes, and snippets.

@AlecsFerra
Created July 30, 2022 19:25
Show Gist options
  • Save AlecsFerra/bc4b7a497ef43ed004cebf1ca11865e9 to your computer and use it in GitHub Desktop.
Save AlecsFerra/bc4b7a497ef43ed004cebf1ca11865e9 to your computer and use it in GitHub Desktop.
Get the last element but in a type safe way
; last
(claim last
(Π ((Of U)
(many-1 Nat)
(vec (Vec Of (add1 many-1))))
Of))
(define last
(λ (Of many-1 vec)
((ind-Nat many-1
(λ (many-1)
(-> (Vec Of (add1 many-1))
Of))
(λ (vec1)
(head vec1))
(λ (n-1 f-1 arg)
(f-1 (tail arg)))) vec)))
; (last Nat 0 (vec:: 1 vecnil))
; (last Nat 1 (vec:: 1 (vec:: 2 vecnil)))
; (last Nat 2 (vec:: 1 (vec:: 2 (vec:: 3 vecnil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment