Why isn't Core_kernel.Time.t sexpable?

I am look to use Core_kernel.Time.t type and found out that it doesn’t have sexp functions, i.e. t_of_sexp, sexp_of_t etc?

All the modules that I am using from Core_kernel seem to have the above defined functions but it seems to be missing from Time.t. Curious as to why? And if we need Time.t sexpable, how do I go about doing it?

https://ocaml.janestreet.com/ocaml-core/latest/doc/core_kernel/Core_kernel__/Time/Make/Time/index.html

To clarify my use case a bit, I am trying to use Time.t as follows,

type t = {
    event: string 
    when: Time.t }
[@@deriving sexp]

The above doesn’t work since Time.t isn’t sexpable. I have resorted to using as below to get around it, but would like to stick to Time.t if possible.

type t = {
    event: string 
    when: Time.Ofday.t * Date.t }
[@@deriving sexp]

I don’t know why Core_kernel.Time.t is not sexpable, but Core.Time.t is. Can you use that instead?

My dependency is core_kernel due to cross os requirements. Would this be an oversight perhaps since core_kernel is advertised as being sexpable?

Core_kernel.Time.t is not directly sexpable like Core.Time.t because the default sexp serialization relies on the non-portable time zone code (i.e., Core.Time.Zone.local exists, but Core_kernel.Time.Zone.local does not).

As an alternative, you could use Core_kernel.Time.Stable.With_utc_sexp.V2.t, which is sexpable and uses UTC for its time zone.

1 Like