PROGRAM 6
(* filename: prog11.sml author: anthony f. ortiz *)
(* this program applies the binary function f to each of the elements *)
(* of the list beginning from the right. *)
fun acc f b nil = b
| acc f b (head :: tail) = f (head, acc f b tail);
acc (op + ) 0 [1, 2, 3, 4, 5];
acc (op * ) 1 [1, 2, 3, 4, 5];
acc (op ^ ) "! " ["hello", " world"];
(* filename: prog11.out author: anthony f. ortiz *)
Standard ML of New Jersey, Version 110.0.6, October 31, 1999 [CM; autoload enabl
ed]
- use "prog11.sml";
[opening prog11.sml]
val acc = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
val it = 15 : int
GC #0.0.0.0.1.9: (10 ms)
val it = 120 : int
val it = "hello world! " : string
val it = () : unit
- ^Z
Stopped (user)
BACK TO CS6140 PAGE.