You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was recently thinking that it might be nice to consider representing DateTimes using Numbat structs.
This would obviously still require some FFI code. We do not want to implementDateTimes in Numbat, we want to use chrono jiff for that. But representing them as structs would have the advantage that we could remove the specialized DateTime code from the type checker and some special operations in the VM. It would also allow us to remove some code that directly refers to Time and second, a connection between the language implementation and the standard library, that I would like to get rid of.
Ignoring timezones for a moment, we could have something like
usecore::dimensionsuseunits::sistructDateTime {
unixtime: Time
}
fnget_current_unixtime() ->Scalar# Implemented via FFIfnnow() =DateTime { unixtime: get_current_unixtime() *second }
Then, if we add full support for Add/Sub type classes (see #462), we could implement addition/subtraction:
Timezone conversions would still work using the x -> f == f(x) trick, but would obviously also go through FFI functions. And parsing/formatting would also go through the FFI.
But the nice thing would be that we could use a unixtime-as-float (+ utc offset for timezone things) interface for that and implement the higher-level stuff in Numbat itself. DateTimes would be a higher-level construct implemented in Numbat alone.
To make this really nice, we would probably need a lot of new language features. In addition to the operator overloading stuff above, we would also require:
Something like a Display type class such that we would see nicely formatted times instead of DateTime { unix_time: 1_718_127_106 s }.
Private struct fields to prevent unwanted access to the internal representation
The text was updated successfully, but these errors were encountered:
I was recently thinking that it might be nice to consider representing
DateTime
s using Numbat structs.This would obviously still require some FFI code. We do not want to implement
DateTime
s in Numbat, we want to usechronojiff for that. But representing them as structs would have the advantage that we could remove the specializedDateTime
code from the type checker and some special operations in the VM. It would also allow us to remove some code that directly refers toTime
andsecond
, a connection between the language implementation and the standard library, that I would like to get rid of.Ignoring timezones for a moment, we could have something like
Then, if we add full support for
Add
/Sub
type classes (see #462), we could implement addition/subtraction:Timezone conversions would still work using the
x -> f == f(x)
trick, but would obviously also go through FFI functions. And parsing/formatting would also go through the FFI.But the nice thing would be that we could use a unixtime-as-float (+ utc offset for timezone things) interface for that and implement the higher-level stuff in Numbat itself.
DateTime
s would be a higher-level construct implemented in Numbat alone.To make this really nice, we would probably need a lot of new language features. In addition to the operator overloading stuff above, we would also require:
Display
type class such that we would see nicely formatted times instead ofDateTime { unix_time: 1_718_127_106 s }
.The text was updated successfully, but these errors were encountered: