Compare commits

...

2 Commits

Author SHA1 Message Date
Stefan Risberg
cc0c6bc1e9 Moved back to dynamic dispatch and bench function 2023-04-17 13:11:02 +02:00
Stefan Risberg
d781295480 Migrated effect to static dispatch 2023-04-17 11:22:21 +02:00
3 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,5 @@
name: ris-utils
version: 0.0.1
version: 0.0.2
homepage: "https://git.fiskhamn.se/steffenomak/ris-utils#readme"
license: BSD3
author: "Stefan Risberg"

View File

@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack
name: ris-utils
version: 0.0.1
version: 0.0.2
description: Please see the README at <https://git.fiskhamn.se/steffenomak/ris-utils#readme>
homepage: https://git.fiskhamn.se/steffenomak/ris-utils#readme
author: Stefan Risberg

View File

@ -2,6 +2,7 @@ module Effects.Time (
currentTime,
currentTimeB,
currentTimeT,
benchFunction,
runTimeEff,
Time,
)
@ -19,6 +20,7 @@ data Time :: Effect where
CurrentTime :: Time m C.Time
CurrentTimeB :: Time m T.Builder
CurrentTimeT :: Time m Text
BenchFunction :: m a -> Time m (Timespan, a)
makeEffect ''Time
@ -26,7 +28,7 @@ runTimeEff ::
(IOE :> es) =>
Eff (Time : es) a ->
Eff es a
runTimeEff = interpret $ \_ -> \case
runTimeEff = interpret $ \env -> \case
CurrentTime -> liftIO now
CurrentTimeB ->
builder_YmdHMS (SubsecondPrecisionFixed 4) w3c . timeToDatetime
@ -34,3 +36,8 @@ runTimeEff = interpret $ \_ -> \case
CurrentTimeT ->
encode_YmdHMS (SubsecondPrecisionFixed 4) w3c . timeToDatetime
<$> liftIO now
BenchFunction f -> do
s <- liftIO now
!d <- localSeqUnlift env $ \unlift -> unlift f
e <- liftIO now
pure (C.width $ s ... e, d)