polysemy-time 0.3.0.0 → 0.4.0.0
raw patch · 13 files changed
+158/−173 lines, 13 filesdep ~incipit-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: incipit-core
API changes (from Hackage documentation)
- Polysemy.Time.Data.Time: [Adjust] :: AddTimeUnit t u1 u2 => u1 -> Time t d m ()
- Polysemy.Time.Data.Time: [Now] :: Time t d m t
- Polysemy.Time.Data.Time: [SetDate] :: d -> Time t d m ()
- Polysemy.Time.Data.Time: [SetTime] :: t -> Time t d m ()
- Polysemy.Time.Data.Time: [Sleep] :: TimeUnit u => u -> Time t d m ()
- Polysemy.Time.Data.Time: [Today] :: Time t d m d
- Polysemy.Time.Data.Time: adjust :: forall t d u1 u2 r. AddTimeUnit t u1 u2 => Member (Time t d) r => u1 -> Sem r ()
- Polysemy.Time.Data.Time: data Time (time :: Type) (date :: Type) :: Effect
- Polysemy.Time.Data.Time: now :: forall t d r. Member (Time t d) r => Sem r t
- Polysemy.Time.Data.Time: setDate :: forall t d r. Member (Time t d) r => d -> Sem r ()
- Polysemy.Time.Data.Time: setTime :: forall t d r. Member (Time t d) r => t -> Sem r ()
- Polysemy.Time.Data.Time: sleep :: forall t d u r. TimeUnit u => Member (Time t d) r => u -> Sem r ()
- Polysemy.Time.Data.Time: today :: forall t d r. Member (Time t d) r => Sem r d
- Polysemy.Time.Data.TimeUnit: divOr0 :: Real a => Integral a => a -> a -> a
- Polysemy.Time.Data.TimeUnit: safeDiv :: Real a => Integral a => a -> a -> Maybe a
- Polysemy.Time.Ghc: interpretTimeGhc :: Member (Embed IO) r => InterpreterFor GhcTime r
- Polysemy.Time.Ghc: interpretTimeGhcAt :: Member (Embed IO) r => UTCTime -> InterpreterFor GhcTime r
- Polysemy.Time.Ghc: interpretTimeGhcConstant :: Member (Embed IO) r => UTCTime -> InterpreterFor GhcTime r
- Polysemy.Time.Ghc: interpretTimeGhcConstantNow :: Member (Embed IO) r => InterpreterFor GhcTime r
- Polysemy.Time.Ghc: type GhcTime = Time UTCTime Day
+ Polysemy.Time.Effect.Time: [Adjust] :: AddTimeUnit t u1 u2 => u1 -> Time t d m ()
+ Polysemy.Time.Effect.Time: [Now] :: Time t d m t
+ Polysemy.Time.Effect.Time: [SetDate] :: d -> Time t d m ()
+ Polysemy.Time.Effect.Time: [SetTime] :: t -> Time t d m ()
+ Polysemy.Time.Effect.Time: [Sleep] :: TimeUnit u => u -> Time t d m ()
+ Polysemy.Time.Effect.Time: [Today] :: Time t d m d
+ Polysemy.Time.Effect.Time: adjust :: forall t d u1 u2 r. AddTimeUnit t u1 u2 => Member (Time t d) r => u1 -> Sem r ()
+ Polysemy.Time.Effect.Time: data Time (time :: Type) (date :: Type) :: Effect
+ Polysemy.Time.Effect.Time: now :: forall t d r. Member (Time t d) r => Sem r t
+ Polysemy.Time.Effect.Time: setDate :: forall t d r. Member (Time t d) r => d -> Sem r ()
+ Polysemy.Time.Effect.Time: setTime :: forall t d r. Member (Time t d) r => t -> Sem r ()
+ Polysemy.Time.Effect.Time: sleep :: forall t d u r. TimeUnit u => Member (Time t d) r => u -> Sem r ()
+ Polysemy.Time.Effect.Time: today :: forall t d r. Member (Time t d) r => Sem r d
+ Polysemy.Time.Interpreter.Ghc: interpretTimeGhc :: Member (Embed IO) r => InterpreterFor GhcTime r
+ Polysemy.Time.Interpreter.Ghc: interpretTimeGhcAt :: Member (Embed IO) r => UTCTime -> InterpreterFor GhcTime r
+ Polysemy.Time.Interpreter.Ghc: interpretTimeGhcConstant :: Member (Embed IO) r => UTCTime -> InterpreterFor GhcTime r
+ Polysemy.Time.Interpreter.Ghc: interpretTimeGhcConstantNow :: Member (Embed IO) r => InterpreterFor GhcTime r
+ Polysemy.Time.Interpreter.Ghc: type GhcTime = Time UTCTime Day
Files
- lib/Polysemy/Time.hs +3/−3
- lib/Polysemy/Time/At.hs +2/−2
- lib/Polysemy/Time/Data/Time.hs +0/−65
- lib/Polysemy/Time/Data/TimeUnit.hs +7/−22
- lib/Polysemy/Time/Effect/Time.hs +65/−0
- lib/Polysemy/Time/Ghc.hs +0/−67
- lib/Polysemy/Time/Interpreter/Ghc.hs +67/−0
- lib/Polysemy/Time/Loop.hs +2/−2
- lib/Polysemy/Time/Measure.hs +2/−2
- lib/Polysemy/Time/Sleep.hs +1/−1
- polysemy-time.cabal +4/−4
- test/Polysemy/Time/Test/GhcTimeTest.hs +3/−3
- test/Polysemy/Time/Test/MeasureTest.hs +2/−2
lib/Polysemy/Time.hs view
@@ -5,7 +5,7 @@ module Polysemy.Time ( -- $intro -- * Time effect- module Polysemy.Time.Data.Time,+ module Polysemy.Time.Effect.Time, GhcTime, -- * Interpreters@@ -43,7 +43,6 @@ HasSecond (..), HasYear (..), )-import Polysemy.Time.Data.Time (Time (..), adjust, now, setDate, setTime, sleep, today) import Polysemy.Time.Data.TimeUnit ( Days (..), Hours (..),@@ -59,7 +58,8 @@ convert, ) import Polysemy.Time.Diff (diff)-import Polysemy.Time.Ghc (+import Polysemy.Time.Effect.Time (Time (..), adjust, now, setDate, setTime, sleep, today)+import Polysemy.Time.Interpreter.Ghc ( GhcTime, interpretTimeGhc, interpretTimeGhcAt,
lib/Polysemy/Time/At.hs view
@@ -5,9 +5,9 @@ import Torsor (Torsor (add), difference) import Polysemy.Time.Calendar (HasDate, date, dateToTime)-import qualified Polysemy.Time.Data.Time as Time-import Polysemy.Time.Data.Time (Time) import Polysemy.Time.Data.TimeUnit (TimeUnit, addTimeUnit)+import qualified Polysemy.Time.Effect.Time as Time+import Polysemy.Time.Effect.Time (Time) -- |Determine the current time adjusted for the difference between a custom instant and the time at which the program -- was started.
− lib/Polysemy/Time/Data/Time.hs
@@ -1,65 +0,0 @@-{-# options_haddock prune #-}---- |Time effect, Internal-module Polysemy.Time.Data.Time where--import Polysemy.Time.Data.TimeUnit (AddTimeUnit, TimeUnit)---- |The Time effect.-data Time (time :: Type) (date :: Type) :: Effect where- -- |Produce the current time, possibly relative to what was set with 'SetTime' or 'SetDate'- Now :: Time t d m t- -- |Produce the current date, possibly relative to what was set with 'SetTime' or 'SetDate'- Today :: Time t d m d- -- |Suspend the current computation for the specified time span.- Sleep :: TimeUnit u => u -> Time t d m ()- -- |Set the current time, if the interpreter supports it.- SetTime :: t -> Time t d m ()- -- |Adjust the current time relatively, if the interpreter supports it.- Adjust :: AddTimeUnit t u1 u2 => u1 -> Time t d m ()- -- |Set the current date, if the interpreter supports it.- SetDate :: d -> Time t d m ()--makeSem_ ''Time---- |Produce the current time, possibly relative to what was set with 'SetTime' or 'SetDate'-now ::- ∀ t d r .- Member (Time t d) r =>- Sem r t---- |Produce the current date, possibly relative to what was set with 'SetTime' or 'SetDate'-today ::- ∀ t d r .- Member (Time t d) r =>- Sem r d---- |Suspend the current computation for the specified time span.-sleep ::- ∀ t d u r .- TimeUnit u =>- Member (Time t d) r =>- u ->- Sem r ()---- |Set the current time, if the interpreter supports it.-setTime ::- ∀ t d r .- Member (Time t d) r =>- t ->- Sem r ()---- |Adjust the current time relatively, if the interpreter supports it.-adjust ::- ∀ t d u1 u2 r .- AddTimeUnit t u1 u2 =>- Member (Time t d) r =>- u1 ->- Sem r ()---- |Set the current date, if the interpreter supports it.-setDate ::- ∀ t d r .- Member (Time t d) r =>- d ->- Sem r ()
lib/Polysemy/Time/Data/TimeUnit.hs view
@@ -1,13 +1,10 @@+{-# options_haddock prune #-}+ -- |TimeUnit Class and Data Types, Internal module Polysemy.Time.Data.TimeUnit where -import Data.Fixed (div')-import Data.Time (- DiffTime,- NominalDiffTime,- diffTimeToPicoseconds,- picosecondsToDiffTime,- )+import Data.Time (DiffTime, NominalDiffTime, diffTimeToPicoseconds, picosecondsToDiffTime)+import qualified GHC.Real as Real import Torsor (Additive, Scaling, Torsor, add, scale) import Polysemy.Time.Json (json)@@ -22,7 +19,7 @@ fromRational secs = FromSeconds (convert (NanoSeconds (round (1e9 * secs)))) FromSeconds a / FromSeconds b =- FromSeconds (a `div` b)+ FromSeconds (a `Real.div` b) -- |Types that represent an amount of time that can be converted to each other. -- The methods are internal, the API function is 'convert'.@@ -37,7 +34,7 @@ fromNanos :: NanoSeconds -> u default fromNanos :: Integral u => NanoSeconds -> u fromNanos n =- fromIntegral (n `div` (nanos @u))+ fromIntegral (n `Real.div` (nanos @u)) -- * Data types used to specify time spans, e.g. for sleeping. @@ -145,18 +142,6 @@ fromNanos = id -safeDiv ::- Real a =>- Integral a =>- a ->- a ->- Maybe a-safeDiv _ 0 =- Nothing-safeDiv n d =- Just (n `div'` d)-{-# inline safeDiv #-}- divOr0 :: Real a => Integral a =>@@ -164,7 +149,7 @@ a -> a divOr0 l r =- fromMaybe 0 (safeDiv l r)+ fromMaybe 0 (div' l r) {-# inline divOr0 #-} instance TimeUnit DiffTime where
+ lib/Polysemy/Time/Effect/Time.hs view
@@ -0,0 +1,65 @@+{-# options_haddock prune #-}++-- |Time effect, Internal+module Polysemy.Time.Effect.Time where++import Polysemy.Time.Data.TimeUnit (AddTimeUnit, TimeUnit)++-- |The Time effect.+data Time (time :: Type) (date :: Type) :: Effect where+ -- |Produce the current time, possibly relative to what was set with 'SetTime' or 'SetDate'+ Now :: Time t d m t+ -- |Produce the current date, possibly relative to what was set with 'SetTime' or 'SetDate'+ Today :: Time t d m d+ -- |Suspend the current computation for the specified time span.+ Sleep :: TimeUnit u => u -> Time t d m ()+ -- |Set the current time, if the interpreter supports it.+ SetTime :: t -> Time t d m ()+ -- |Adjust the current time relatively, if the interpreter supports it.+ Adjust :: AddTimeUnit t u1 u2 => u1 -> Time t d m ()+ -- |Set the current date, if the interpreter supports it.+ SetDate :: d -> Time t d m ()++makeSem_ ''Time++-- |Produce the current time, possibly relative to what was set with 'SetTime' or 'SetDate'+now ::+ ∀ t d r .+ Member (Time t d) r =>+ Sem r t++-- |Produce the current date, possibly relative to what was set with 'SetTime' or 'SetDate'+today ::+ ∀ t d r .+ Member (Time t d) r =>+ Sem r d++-- |Suspend the current computation for the specified time span.+sleep ::+ ∀ t d u r .+ TimeUnit u =>+ Member (Time t d) r =>+ u ->+ Sem r ()++-- |Set the current time, if the interpreter supports it.+setTime ::+ ∀ t d r .+ Member (Time t d) r =>+ t ->+ Sem r ()++-- |Adjust the current time relatively, if the interpreter supports it.+adjust ::+ ∀ t d u1 u2 r .+ AddTimeUnit t u1 u2 =>+ Member (Time t d) r =>+ u1 ->+ Sem r ()++-- |Set the current date, if the interpreter supports it.+setDate ::+ ∀ t d r .+ Member (Time t d) r =>+ d ->+ Sem r ()
− lib/Polysemy/Time/Ghc.hs
@@ -1,67 +0,0 @@-{-# options_haddock prune #-}---- |'Time' interpreters for the data types from "Data.Time", Internal-module Polysemy.Time.Ghc where--import Control.Concurrent (threadDelay)-import Data.Time (Day, NominalDiffTime, UTCTime, utctDay)-import Data.Time.Clock.System (getSystemTime, systemToUTCTime)--import Polysemy.Time.At (interceptTimeAt, interceptTimeConstant, interceptTimeConstantNow)-import qualified Polysemy.Time.Data.Time as Time-import Polysemy.Time.Data.Time (Time)-import Polysemy.Time.Data.TimeUnit (MicroSeconds (MicroSeconds), convert)-import Polysemy.Time.Orphans ()---- |Convenience alias for 'Data.Time'.-type GhcTime =- Time UTCTime Day--now ::- Member (Embed IO) r =>- Sem r UTCTime-now =- systemToUTCTime <$> embed getSystemTime---- |Interpret 'Time' with the types from 'Data.Time'.-interpretTimeGhc ::- Member (Embed IO) r =>- InterpreterFor GhcTime r-interpretTimeGhc =- interpret \case- Time.Now ->- now- Time.Today ->- utctDay <$> now- Time.Sleep (convert -> MicroSeconds us) ->- embed (threadDelay (fromIntegral us))- Time.SetTime _ ->- unit- Time.Adjust _ ->- unit- Time.SetDate _ ->- unit---- |Interpret 'Time' with the types from 'Data.Time', customizing the current time at the start of interpretation.-interpretTimeGhcAt ::- Member (Embed IO) r =>- UTCTime ->- InterpreterFor GhcTime r-interpretTimeGhcAt t =- interpretTimeGhc . interceptTimeAt @NominalDiffTime t---- |Interpret 'Time' with the types from 'Data.Time', customizing the current time to be constant.-interpretTimeGhcConstant ::- Member (Embed IO) r =>- UTCTime ->- InterpreterFor GhcTime r-interpretTimeGhcConstant t =- interpretTimeGhc . interceptTimeConstant t---- |Interpret 'Time' with the types from 'Data.Time', customizing the current time to be constantly the time at the--- start of interpretation.-interpretTimeGhcConstantNow ::- Member (Embed IO) r =>- InterpreterFor GhcTime r-interpretTimeGhcConstantNow =- interpretTimeGhc . interceptTimeConstantNow @UTCTime
+ lib/Polysemy/Time/Interpreter/Ghc.hs view
@@ -0,0 +1,67 @@+{-# options_haddock prune #-}++-- |'Time' interpreters for the data types from "Data.Time", Internal+module Polysemy.Time.Interpreter.Ghc where++import Control.Concurrent (threadDelay)+import Data.Time (Day, NominalDiffTime, UTCTime, utctDay)+import Data.Time.Clock.System (getSystemTime, systemToUTCTime)++import Polysemy.Time.At (interceptTimeAt, interceptTimeConstant, interceptTimeConstantNow)+import qualified Polysemy.Time.Effect.Time as Time+import Polysemy.Time.Effect.Time (Time)+import Polysemy.Time.Data.TimeUnit (MicroSeconds (MicroSeconds), convert)+import Polysemy.Time.Orphans ()++-- |Convenience alias for 'Data.Time'.+type GhcTime =+ Time UTCTime Day++now ::+ Member (Embed IO) r =>+ Sem r UTCTime+now =+ systemToUTCTime <$> embed getSystemTime++-- |Interpret 'Time' with the types from 'Data.Time'.+interpretTimeGhc ::+ Member (Embed IO) r =>+ InterpreterFor GhcTime r+interpretTimeGhc =+ interpret \case+ Time.Now ->+ now+ Time.Today ->+ utctDay <$> now+ Time.Sleep (convert -> MicroSeconds us) ->+ embed (threadDelay (fromIntegral us))+ Time.SetTime _ ->+ unit+ Time.Adjust _ ->+ unit+ Time.SetDate _ ->+ unit++-- |Interpret 'Time' with the types from 'Data.Time', customizing the current time at the start of interpretation.+interpretTimeGhcAt ::+ Member (Embed IO) r =>+ UTCTime ->+ InterpreterFor GhcTime r+interpretTimeGhcAt t =+ interpretTimeGhc . interceptTimeAt @NominalDiffTime t++-- |Interpret 'Time' with the types from 'Data.Time', customizing the current time to be constant.+interpretTimeGhcConstant ::+ Member (Embed IO) r =>+ UTCTime ->+ InterpreterFor GhcTime r+interpretTimeGhcConstant t =+ interpretTimeGhc . interceptTimeConstant t++-- |Interpret 'Time' with the types from 'Data.Time', customizing the current time to be constantly the time at the+-- start of interpretation.+interpretTimeGhcConstantNow ::+ Member (Embed IO) r =>+ InterpreterFor GhcTime r+interpretTimeGhcConstantNow =+ interpretTimeGhc . interceptTimeConstantNow @UTCTime
lib/Polysemy/Time/Loop.hs view
@@ -1,8 +1,8 @@ -- |Combinators for looping with a sleep interval, Internal module Polysemy.Time.Loop where -import qualified Polysemy.Time.Data.Time as Time-import Polysemy.Time.Data.Time (Time)+import qualified Polysemy.Time.Effect.Time as Time+import Polysemy.Time.Effect.Time (Time) import Polysemy.Time.Data.TimeUnit (TimeUnit) -- |Repeatedly run the @action@, sleeping for @interval@ between executions.
lib/Polysemy/Time/Measure.hs view
@@ -4,10 +4,10 @@ import Torsor (Torsor) import Polysemy.Time.Class.Instant (Instant)-import qualified Polysemy.Time.Data.Time as Time-import Polysemy.Time.Data.Time (Time) import Polysemy.Time.Data.TimeUnit (TimeUnit) import Polysemy.Time.Diff (diff)+import qualified Polysemy.Time.Effect.Time as Time+import Polysemy.Time.Effect.Time (Time) -- |Run the action @ma@ and measure the time it takes. --
lib/Polysemy/Time/Sleep.hs view
@@ -1,4 +1,4 @@-{-# options_haddock prune, hide #-}+{-# options_haddock prune #-} -- |Helpers for sleeping, Internal module Polysemy.Time.Sleep where
polysemy-time.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-time-version: 0.3.0.0+version: 0.4.0.0 synopsis: Polysemy Effect for Time description: Please see the readme on Github at <https://github.com/tek/polysemy-time> category: Time@@ -25,10 +25,10 @@ Polysemy.Time.At Polysemy.Time.Calendar Polysemy.Time.Class.Instant- Polysemy.Time.Data.Time Polysemy.Time.Data.TimeUnit Polysemy.Time.Diff- Polysemy.Time.Ghc+ Polysemy.Time.Effect.Time+ Polysemy.Time.Interpreter.Ghc Polysemy.Time.Json Polysemy.Time.Loop Polysemy.Time.Measure@@ -98,7 +98,7 @@ build-depends: aeson >=1.4 , base ==4.*- , incipit-core >=0.1+ , incipit-core >=0.2 , stm , template-haskell , time
test/Polysemy/Time/Test/GhcTimeTest.hs view
@@ -5,10 +5,10 @@ import Polysemy.Test.Data.Hedgehog (Hedgehog) import Polysemy.Time.Calendar (mkDatetime, year)-import qualified Polysemy.Time.Data.Time as Time-import Polysemy.Time.Data.Time (Time)+import qualified Polysemy.Time.Effect.Time as Time+import Polysemy.Time.Effect.Time (Time) import Polysemy.Time.Data.TimeUnit (Days (Days), Seconds (Seconds))-import Polysemy.Time.Ghc (interpretTimeGhc, interpretTimeGhcAt)+import Polysemy.Time.Interpreter.Ghc (interpretTimeGhc, interpretTimeGhcAt) prog :: ∀ t d r .
test/Polysemy/Time/Test/MeasureTest.hs view
@@ -3,9 +3,9 @@ import Data.Time (Day, UTCTime) import Polysemy.Test (UnitTest, assert, runTestAuto) -import qualified Polysemy.Time.Data.Time as Time+import qualified Polysemy.Time.Effect.Time as Time import Polysemy.Time.Data.TimeUnit (MilliSeconds (MilliSeconds), convert)-import Polysemy.Time.Ghc (interpretTimeGhc)+import Polysemy.Time.Interpreter.Ghc (interpretTimeGhc) import Polysemy.Time.Measure (measure) test_measure :: UnitTest