[ base ] add total last to List1

This commit is contained in:
Guillaume ALLAIS 2020-08-05 12:09:35 +01:00
parent 2425e76a1e
commit cd0d7d692b
2 changed files with 9 additions and 1 deletions

View File

@ -318,7 +318,7 @@ public export
last : (l : List a) -> {auto ok : NonEmpty l} -> a
last [] impossible
last [x] = x
last (x::y::ys) = last (y::ys)
last (x::y::ys) = List.last (y::ys)
||| Return all but the last element of a non-empty list.
||| @ ok proof the list is non-empty

View File

@ -8,6 +8,14 @@ record List1 a where
head : a
tail : List a
export
last : List1 a -> a
last (x :: xs) = go x xs where
go : a -> List a -> a
go x [] = x
go _ (y :: ys) = go y ys
public export
toList : (1 xs : List1 a) -> List a
toList (x :: xs) = x :: xs