adamc@397: datatype list t = Nil | Cons of t * list t adamc@397: adamc@397: fun length' (t ::: Type) (ls : list t) (acc : int) = adamc@397: case ls of adamc@397: Nil => acc adamc@397: | Cons (_, ls') => length' ls' (acc + 1) adamc@397: adamc@397: fun length (t ::: Type) (ls : list t) = length' ls 0 adamc@397: adamc@397: fun rev' (t ::: Type) (ls : list t) (acc : list t) = adamc@397: case ls of adamc@397: Nil => acc adamc@397: | Cons (x, ls') => rev' ls' (Cons (x, acc)) adamc@397: adamc@397: fun rev (t ::: Type) (ls : list t) = rev' ls Nil