- Notifications
You must be signed in to change notification settings - Fork5
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 theTimeexception should be raised. Specifically, it states
These convert the number n to a
timevalue denoting n seconds (respectively, milliseconds, microseconds, or nanoseconds).If the result is not representable by the time type, then the exceptionTimeis raised.
which would suggest that theTime exception could be raised when there is a loss ofprecision 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 : timeThe description of theTime.fromSecondsand related operations should be rewritten as follows:
These convert the number n to a
timevalue denoting n seconds (respectively, milliseconds, microseconds, or nanoseconds).This conversion is truncated toward zero (as done byInt.quot) if necessary. Ifthe value is too large to be represented as aTime.timevalue, then the exceptionTimeis raised.
In addition, we add thetick value (see the discussion for alternatives)with the following description:
tick
the smallest representable time quanta. Specifying avalue smaller than this usingfromNanoseconds(or similar function) will result inzeroTime.
There is a question of whattick should represent and if it should be a function orjust aTime.time value. Some possible choices are
Have
tickbe aTime.timevalue that is the smallest time value representableas aTime.timevalue. This value is unrelated to the underlying operating-system'ssmallest time quanta.Have
tickbe aTime.timevalue that is the host system's smallest time quanta.The assumption is that the value is representable as aTime.timevalue. One concernis that an operating system might support configuring the time quanta so that thisvalue could be incorrect if a program is run on a different machine from where itwas compiled.Have
tickbe aunit -> Time.timefunction that returns the host system'ssmallest time quanta. This choice addresses the second issue with the previouschoice.Have the representation of
tickbe anIntInf.intnumber of nanoseconds, insteadof aTime.timevalue. This choice is compatible with the previous choices.An integer value may be more useful than aTime.timevalue.
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 itshould not affect any existing code. Adding thetick value or function shouldnot break any code.
This proposal makes explicit the ordering of effects for these functions, which will improveconsistency across implementations.
- [2024-11-18] Proposed
