Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NominalDiffTime to Real

Tags:

haskell

In the documentation for Data.Time.Clock I see this:

Conversion functions will treat it as seconds. It has a precision of 10^-12 s

What function will turn that NominalDiffTime into a Double? No luck hoogling it

like image 333
Cuadue Avatar asked Dec 22 '13 18:12

Cuadue


1 Answers

You need to pay more attention to the list of instances for the type. One of the listed instances is Real NominalDiffTime. This allows you to use realToFrac :: (Real a, Fractional b) :: a -> b to convert to Double, since Double is an instance of Fractional.

Since NominalDiffTime has a Real instance, and Double has a Fractional instance, you can use realToFrac as if it had the type signature NominalDiffTime -> Double. Of course, realToFrac is more polymorphic than that, and so you might need to give it hints exactly what types you want to convert sometimes. But it certainly is capable of that conversion, if it can figure out the types.

like image 191
Carl Avatar answered Sep 25 '22 09:09

Carl