Case 1) The forall function conceptually modifies the contents of the set
'S'. It doesn't seem to be possible to modify the contents of the set
'in place', because S is a function, and you can't go ripping apart a
function. So the only possibility would be for 'S' to be passed by name,
so that you can change what S points to.
The problem with this approach would be that you could only pass Ref's
to sets to the forall function. ie, the following would be invalid
> val a = newset [1,2,3];
> forall a (fn x => x+1);
Case 2) We are not interested in modifying the value of S at all. It is
in fact the function F which has side effects. For example, if you
wanted to print the contents of S, you could say
> forall S Print;
Where Print is some ML function which prints an int as a side-effect.
For question 1, which of these are we supposed to implement? Or is there
some possibility which I have overlooked? For question 2, I presume the
forall function is to behave similarly to Scheme's 'map'?
Thanks,
- Nick
--
--
Nick Harvey
PGP signed and encrypted email preferred
finger njah...@undergrad.math.uwaterloo.ca for PGP key
You implement the second. I/O is not the only way to achieve side-effects.
For example, you could access a variable. The following example sums
the elements of a set of integers named a:
let
val x = ref 0;
in
(forall a (fn y => (!x := !x + y)); !x)
end
--
Gordon V. Cormack CS Dept, University of Waterloo, Canada N2L 3G1
gvco...@uwaterloo.ca http://cormack.uwaterloo.ca/cormack