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 name: ris-utils
version: 0.0.1 version: 0.0.2
homepage: "https://git.fiskhamn.se/steffenomak/ris-utils#readme" homepage: "https://git.fiskhamn.se/steffenomak/ris-utils#readme"
license: BSD3 license: BSD3
author: "Stefan Risberg" author: "Stefan Risberg"

View File

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

View File

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