Looks like a strange difference between [1,2,3] and [1..3].
Using runghc on the following prints out one "True" and then hangs forever: why? (I'm using ghc 7.8.3)
module Main where
import Data.Functor((<$>))
import Data.Time.Clock(DiffTime)
import Data.Binary(Binary(..), encode, decode, Get)
import Data.Int(Int64)
instance Binary DiffTime where
put x = put (truncate (x * 10^12) :: Int64)
get = ((/ 10^12) . fromIntegral) <$> (get :: Get Int64)
prop_getput_difftime :: DiffTime -> Bool
prop_getput_difftime x = x == ((decode . encode $ x) :: DiffTime)
explicit :: [DiffTime]
explicit = [1,2,3,4,5,6,7,8,9,10]
elipsis :: [DiffTime]
elipsis = [1..10]
main :: IO ()
main = do
print $ all prop_getput_difftime explicit
print $ all prop_getput_difftime elipsis -- diverges!
Note, the above implementation of Binary for DiffTime is wrong; but that is beside the point.
Thanks to otulp from #haskell, here's the reason:
Prelude> take 3 [1..2] :: [Data.Time.DiffTime]
[1s,1.000000000001s,1.000000000002s]
Which happens because of the Enum
instance for DiffTime
Changing elipsis
to this fixes the problem:
elipsis = map fromIntegral ([1..10] :: [Int])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With