[m-rev.] for review: print formatted dates and durations with io.print

Julien Fischer jfischer at opturion.com
Wed Dec 24 00:38:03 AEDT 2014


Hi,

On Mon, 22 Dec 2014, Sebastian Godelet wrote:

> On Mon, 22 Dec 2014 11:11:40 +1100 (AEDT)
> Julien Fischer <jfischer at opturion.com> wrote:
>
>>
>> Print formatted dates and durations with io.print.
>
> In the io.print documentation it is mentioned that values will be
> print in a human-readable form, would you consider a string
> representation like in ISO 8601, such as: 2014-12-19T16:05:00:00Z
> as human-readable?
>
> I think it would be confusing for a user to see durations printed in
> an ISO 8601 format, but not the date_times.

Strictly speaking, Mercury does not claim to conform with the ISO 8601
date and duration formats.  (It doesn't set out to *not* conform with
them, the matter just isn't mentioned one way or another.)

> One problem with the current time implementation is that the time zone
> information (or at least the offset, or UTC/local) is irreversibly lost.

There are numerous problems with both the time and (to a lesser extent)
the calender module.  Handling of time zone information is one of them.

> For a start maybe a UTC/local boolean could be stored in the time.tm
> representation.

Note that time.tm and calendar.date_time are different things.

> Another question I have is how a user can hook the print mechanism for
> custom types, unfortunately there is no typeclass such as
> stringifiable(T) with to_string(T) = string or similar.

The idea is that if runtime type class membership tests are ever
supported, they can be used to implement such a hook (e.g. if a type is
an instance of stringifiable/1 -- or whatever it ends up being called --
then that is used to format the value.)  See comments in the clauses
for print_quoted in library/stream.string_writer.m for details.

> I have read in the manual that the current usage of typeclasses in the
> standard library is due to historical reasons, are there (still) any
> technical restrictions on adding a typeclass for this purpose?

For the specific case of io.print, in the absence of the runtime
membership test I mentioned above it wouldn't help.  The reason it
wouldn't help is that io.print is intended to work for all types, not
just those that are instances of the stringifiable type class.

Cheers,
Julien.



More information about the reviews mailing list