Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on Time.from* functions' behavior #35

Open
Skyb0rg007 opened this issue Mar 14, 2024 · 6 comments
Open

Clarification on Time.from* functions' behavior #35

Skyb0rg007 opened this issue Mar 14, 2024 · 6 comments

Comments

@Skyb0rg007
Copy link

Skyb0rg007 commented Mar 14, 2024

The documentation for Time.fromSeconds, Time.fromMilliseconds, Time.fromMicroseconds, and Time.fromNanoseconds is (emphasis mine):

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 exception Time is raised.

The wording here makes it seem like an implementation should raise the Time exception when the time is too precise for the implementation, but this does not seem to be implemented in practice.

val t = Time.fromNanoseconds 1
val nsec = Time.toNanoseconds t
val () = TextIO.print ("Nanoseconds: " ^ LargeInt.toString nsec ^ "\n")

(* MLton *)
Nanoseconds: 1
(* SML/NJ *)
Nanoseconds: 0
(* Poly/ML *)
Nanoseconds: 0

Proposal:
Make clear what the expected behaviors of the Time conversion functions are.
This could be done by adding the sentence from the Time.fromReal function:

Depending on the resolution of time, fractions of a microsecond may be lost.

@JohnReppy
Copy link
Contributor

I do not remember the rationale for that language, but I suspect that the intention was focused on overflowing the internal representation (rather than underflow).

It might also be useful to add a constant

val tick : time

to the interface that is minimum representable unit of time.

@JohnReppy
Copy link
Contributor

See proposal 2024-001 (Clarification of Time module operations) for the companion proposal.

@dmacqueen
Copy link

dmacqueen commented Nov 19, 2024 via email

@JohnReppy
Copy link
Contributor

Thanks for pointing that out. I've removed the word "of", which should make it understandable.

@dmacqueen
Copy link

dmacqueen commented Nov 20, 2024 via email

@Skyb0rg007
Copy link
Author

I made the edits discussed yesterday to align the synopsis with the discussion sections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants