[Haskell-cafe] Converting CTime -> Int

Tomasz Zielonka tomasz.zielonka at gmail.com
Wed May 16 03:35:44 EDT 2007


On Wed, May 16, 2007 at 12:38:55AM -0400, Brandon S. Allbery KF8NH wrote:
> On May 16, 2007, at 0:35 , Rob Hoelz wrote:
> 
> >wrapping returns time_t.  I see that this maps to CTime in
> >Foreign.C.Types, but I can't figure out how to convert it to an Int  
> >(or
> >any other useful Haskell type, for that matter) for the life of me.
> >I've poured over the standard library docs, but to no avail.  Could
> >someone give me a hint?
> 
> It's an instance of Enum, so use fromEnum to create an Int.  (Don't  
> feel too bad, it took me an embarrasingly long amount of time to  
> figure that out as well; before that I used read . show :)

I'm not sure it's a good idea - in theory, Int can have fewer bits than
CTime.

I wonder why CTime is not Integral - maybe there is no such guarantee
for time_t? If so, then you shouldn't rely on Enum. The safest bet seems
to be toRational - CTime is Real.

Best regards
Tomek


More information about the Haskell-Cafe mailing list