module Polysemy.Time.Measure where
import Torsor (Torsor)
import Polysemy.Time.Class.Instant (Instant)
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)
measure ::
∀ dt t d u r a .
TimeUnit u =>
Torsor dt u =>
Instant t dt =>
Member (Time t d) r =>
Sem r a ->
Sem r (u, a)
measure :: forall dt t d u (r :: EffectRow) a.
(TimeUnit u, Torsor dt u, Instant t dt, Member (Time t d) r) =>
Sem r a -> Sem r (u, a)
measure Sem r a
ma = do
!t
start <- forall t d (r :: EffectRow). Member (Time t d) r => Sem r t
Time.now @t @d
a
a <- Sem r a
ma
!t
end <- forall t d (r :: EffectRow). Member (Time t d) r => Sem r t
Time.now @t @d
pure (forall dt u i1 i2 diff.
(TimeUnit diff, TimeUnit u, Torsor dt diff, Instant i1 dt,
Instant i2 dt) =>
i1 -> i2 -> u
diff t
end t
start, a
a)
{-# inline measure #-}