Added length function

This commit is contained in:
William J. Bowman 2016-01-19 11:10:58 -05:00
parent b0a5f3fc09
commit 3a644fae90
No known key found for this signature in database
GPG Key ID: DDD48D26958F0D1A

View File

@ -8,7 +8,8 @@
List
nil
cons
list-ref)
list-ref
length)
(data List : (-> (A : Type) Type)
(nil : (-> (A : Type) (List A)))
@ -23,3 +24,10 @@
[z (some A a)]
[(s (n-1 : Nat))
((recur rest) n-1)]))]))
(define (length (A : Type) (ls : (List A)))
(match ls
[(nil (A : Type))
z]
[(cons (A : Type) (a : A) (rest : (List A)))
(s (recur rest))]))