haskell / time

A time library

Home Page:http://hackage.haskell.org/package/time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

instance Random DiffTime

domenkozar opened this issue · comments

instance Random DiffTime where
  random :: (RandomGen g) => g -> (DiffTime, g)
  random g =
    let (i, g') = random g
     in (picosecondsToDiffTime $ fromIntegral (i :: Integer), g')

  randomR :: RandomGen g => (DiffTime, DiffTime) -> g -> (DiffTime, g)
  randomR (a, b) g =
    let (i, g') = randomR (diffTimeToPicoseconds a, diffTimeToPicoseconds b) g
     in (picosecondsToDiffTime i, g')

Hello, what's the issue here?

I'm in a need of such instance, so I figured I'd open an issue.

That this should be added to the time library, is that correct?

This means taking a package dependency on random -- this might be OK but I need to check.

Currently random depends on splitmix which depends on time, so the code can't go here. You'll have to put in the random package instead.

Currently random depends on splitmix which depends on time, so the code can't go here. You'll have to put in the random package instead.

I believe this is only the case for non-ghc compilers. I think they are trying to avoid depending on time there.

time is a GHC boot package and should not depend on non-boot packages (such as random).