Reversing a List: Using Patterns
fun rev2(nil) = nil |
rev2(a::b) = rev2(a)@[b];
val rev2 : fn 'a list -> 'a list
rev2 [1, 2, 3, 4];
val it = [4, 3, 2, 1] : int list
rev2 [1.0, 1.2, 1.3];
val it = [1.3, 1.2, 1.0] : real list
Previous slide
Next slide
Back to first slide
View graphic version