Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question 1

1 view
Skip to first unread message

Nick Harvey

unread,
Feb 16, 1998, 3:00:00 AM2/16/98
to

I was wondering about the 'forall' function for question 1. Since forall
returns (), it must have some sort of side-effects to be useful. There seem
to be two possibilities:

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

Gordon V. Cormack

unread,
Feb 16, 1998, 3:00:00 AM2/16/98
to

In article <EoHrv...@undergrad.math.uwaterloo.ca>,

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

0 new messages