Using QuickCheck, I'd like to create a series of pseudorandom TimeOfDay
values.
It's easy to create a specific TimeOfDay
:
now = TimeOfDay 17 35 22
Printing this with GHCi 8.6.5 yields:
17:35:22
I thought that the Arbitrary
instance necessary for creating TimeOfDay
values with QuickCheck would thus be:
instance Arbitrary TimeOfDay where
arbitrary = do
hour <- elements [0 .. 23]
min <- elements [0 .. 59]
-- Going till 60 accounts for leap seconds
sec <- elements [0 .. 60]
return $ TimeOfDay hour min sec
Although this typechecks, running the following line hangs GHCi and after a couple of seconds writes Killed
to the console:
sample (arbitrary :: Gen TimeOfDay)
Where's the bug?
Enum
instance. Of course,Enum
is terminally broken, but that takes the cake. – Bryanbryana