Skip to content

Commit e916a52

Browse files
committed
Show Time instance
> show (Time 1) Time 1 instead of the default (via DiffTime) > show (Time 1) Time 1s This is useful when copy pasting counterexamples to source files.
1 parent 4f5a4cd commit e916a52

File tree

1 file changed

+6
-2
lines changed
  • io-classes/si-timers/src/Control/Monad/Class/MonadTime

1 file changed

+6
-2
lines changed

io-classes/si-timers/src/Control/Monad/Class/MonadTime/SI.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,27 @@ import Control.Monad.Class.MonadTime qualified as MonadTime
2626

2727
import NoThunks.Class (NoThunks (..))
2828

29+
import Data.Fixed (Pico, showFixed)
2930
import Data.Time.Clock (DiffTime)
3031
import Data.Time.Clock qualified as Time
3132
import Data.Word (Word64)
3233
import GHC.Generics (Generic (..))
3334

3435

35-
-- | A point in time in a monotonic clock.
36+
-- | A point in time in a monotonic clock counted in seconds.
3637
--
3738
-- The epoch for this clock is arbitrary and does not correspond to any wall
3839
-- clock or calendar, and is /not guaranteed/ to be the same epoch across
3940
-- program runs. It is represented as the 'DiffTime' from this arbitrary epoch.
4041
--
4142
newtype Time = Time DiffTime
42-
deriving stock (Eq, Ord, Show, Generic)
43+
deriving stock (Eq, Ord, Generic)
4344
deriving newtype NFData
4445
deriving anyclass NoThunks
4546

47+
instance Show Time where
48+
show (Time t) = "Time " ++ showFixed True (realToFrac t :: Pico)
49+
4650
-- | The time duration between two points in time (positive or negative).
4751
diffTime :: Time -> Time -> DiffTime
4852
diffTime (Time t) (Time t') = t - t'

0 commit comments

Comments
 (0)