time icon indicating copy to clipboard operation
time copied to clipboard

Allow `Posix` to flow through ports

Open elliotdickison opened this issue 7 years ago • 0 comments

TL;DR

Would it be possible to make Posix a type that could flow freely over ports?

Background

I'm in the progress of upgrading a project from 0.18 to 0.19 (new release looks great, thanks!) and ran into a slight hiccup with the new Posix type. Unlike the old Time type which was just an alias for Float, the new Posix type is opaque so I can't use it interchangeably with it's basic type (now Int in 0.19). I actually like that this forces me to use Posix consistently everywhere.

The issue is that I used to send a lot of records containing timestamps over ports. In 0.18 this worked seamlessly with time values being treated as Floats, but now I get errors like the following one:

The `user` port is trying to transmit a `Posix` value:

87| port user : User -> Cmd msg
         ^^^^^^^^^^^^
I cannot handle that. The types that CAN flow in and out of Elm include:

    Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, tuples, records, and
    JSON values.

Given that Posix is really just an Int (and is unlikely to ever change given the nature of that data) it seems a shame to have to create a new record type and manually covert Posix to Int before sending the data over the port. Would it be possible to make Posix a type that could flow freely over ports? I don't know how much work that involves and I'm not sure if there might be unintended consequences to this proposal, but I wanted to throw it out there.

elliotdickison avatar Sep 02 '18 03:09 elliotdickison