[Haskell-cafe] No instance for (Read POSIXTime)

Yitzchak Gale gale at sefer.org
Mon Dec 12 11:17:40 CET 2011


dokondr wrote:
> All I actually need
> is some way to get *seconds* since epoch from the system, so I could
> manipulate them as integers.

Well, you already have that - that's exactly what POSIXTime
is. It is a numerical type, an instance of the RealFrac
class. So perhaps you can do all of your calculations within
that type itself, without converting it to anything else.

If you really do need to convert it, *please* don't do
that by going all the way to String and back!
Just cast it or convert like you would any other
numerical type.

To make it a Fractional, like Float, Double, or Rational,
use realToFrac.

Since POSIX allows time to be specified with
granularity much finer than seconds, the POSIXTime
type is not an instance of Integral. (Even on
operating systems where POSIX does happen to
be counted in whole seconds.)
So to get to an Integral type, you'll need to use
some kind of rounding function, like round, floor,
or ceiling.

Regards,
Yitz



More information about the Haskell-Cafe mailing list