-
Notifications
You must be signed in to change notification settings - Fork 4
2024 001 Clarification of Time module operations
Author: John Reppy and Skye Soss
Last revised: November 18, 2024
Status: proposed
Discussion: issue #35
The specification of the functions that create time values from numbers of seconds, etc.
is not clear about when the Time
exception should be raised. Specifically, it states
These convert the number n to a
time
value denoting n seconds (respectively, milliseconds, microseconds, or nanoseconds). If the result is not representable by the time type, then the exceptionTime
is raised.
which would suggest that the Time
exception could be raised when there is a loss of
precision in the result.
This proposal clarifies the intended semantics for these operations and, in addition, adds a function for determining the precision supported by time values.
val tick : time
The description of the Time.fromSeconds
and related operations should be rewritten as follows:
These convert the number n to a
time
value denoting n seconds (respectively, milliseconds, microseconds, or nanoseconds). This conversion is truncated toward zero (as done byInt.quot
) if necessary. If the value is too large to be represented as aTime.time
value, then the exceptionTime
is raised.
In addition, we add the tick
value (see the discussion for alternatives)
with the following description:
-
tick
the smallest representable time quanta. Specifying a value smaller than this usingfromNanoseconds
(or similar function) will result inzeroTime
.
There is a question of what tick
should represent and if it should be a function or
just a Time.time
value. Some possible choices are
-
Have
tick
be aTime.time
value that is the smallest time value representable as aTime.time
value. This value is unrelated to the underlying operating-system's smallest time quanta. -
Have
tick
be aTime.time
value that is the host system's smallest time quanta. The assumption is that the value is representable as aTime.time
value. One concern is that an operating system might support configuring the time quanta so that this value could be incorrect if a program is run on a different machine from where it was compiled. -
Have
tick
be aunit -> Time.time
function that returns the host system's smallest time quanta. This choice addresses the second issue with the previous choice. -
Have the representation of
tick
be anIntInf.int
number of nanoseconds, instead of aTime.time
value. This choice is compatible with the previous choices. An integer value may be more useful than aTime.time
value.
We are currently proposing the first choice, but one of the others might be better.
This proposal follows existing practice in known SML implementations, so it
should not affect any existing code. Adding the tick
value or function should
not break any code.
This proposal makes explicit the ordering of effects for these functions, which will improve consistency across implementations.
- [2024-11-18] Proposed