Created
July 30, 2022 19:25
-
-
Save AlecsFerra/bc4b7a497ef43ed004cebf1ca11865e9 to your computer and use it in GitHub Desktop.
Get the last element but in a type safe way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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