comparison demo/list.ur @ 823:669ac5e9a69e

Demo compiles with pattern-matching-fu
author Adam Chlipala <adamc@hcoop.net>
date Thu, 28 May 2009 10:35:25 -0400
parents 7ef4b2911b09
children
comparison
equal deleted inserted replaced
822:d4e811beb8eb 823:669ac5e9a69e
1 datatype list t = Nil | Cons of t * list t 1 datatype list t = Nil | Cons of t * list t
2 2
3 fun length (t ::: Type) (ls : list t) = 3 fun length [t] (ls : list t) =
4 let 4 let
5 fun length' (ls : list t) (acc : int) = 5 fun length' (ls : list t) (acc : int) =
6 case ls of 6 case ls of
7 Nil => acc 7 Nil => acc
8 | Cons (_, ls') => length' ls' (acc + 1) 8 | Cons (_, ls') => length' ls' (acc + 1)
9 in 9 in
10 length' ls 0 10 length' ls 0
11 end 11 end
12 12
13 fun rev (t ::: Type) (ls : list t) = 13 fun rev [t] (ls : list t) =
14 let 14 let
15 fun rev' (ls : list t) (acc : list t) = 15 fun rev' (ls : list t) (acc : list t) =
16 case ls of 16 case ls of
17 Nil => acc 17 Nil => acc
18 | Cons (x, ls') => rev' ls' (Cons (x, acc)) 18 | Cons (x, ls') => rev' ls' (Cons (x, acc))