monad-time-effectful (empty) → 1.0.0.0
raw patch · 5 files changed
+129/−0 lines, 5 filesdep +basedep +effectful-coredep +monad-time
Dependencies added: base, effectful-core, monad-time, time
Files
- CHANGELOG.md +2/−0
- LICENSE +20/−0
- README.md +10/−0
- monad-time-effectful.cabal +49/−0
- src/Effectful/Time.hs +48/−0
+ CHANGELOG.md view
@@ -0,0 +1,2 @@+# monad-time-effectful-1.0.0.0 (2023-06-19)+* Initial release.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2021 Hécate Moonlight++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,10 @@+# monad-time-effectful++[](https://github.com/haskell-effectful/monad-time-effectful/actions?query=branch%3Amaster)+[](https://hackage.haskell.org/package/monad-time-effectful)+[](https://packdeps.haskellers.com/feed?needle=andrzej@rybczak.net)+[](https://www.stackage.org/lts/package/monad-time-effectful)+[](https://www.stackage.org/nightly/package/monad-time-effectful)+++Adaptation of the [monad-time](https://hackage.haskell.org/package/monad-time) library for the [effectful](https://hackage.haskell.org/package/effectful) ecosystem.
+ monad-time-effectful.cabal view
@@ -0,0 +1,49 @@+cabal-version: 2.4+build-type: Simple+name: monad-time-effectful+version: 1.0.0.0+license: MIT+license-file: LICENSE+category: Control+maintainer: andrzej@rybczak.net+author: Andrzej Rybczak, Hécate Moonlight++synopsis: Adaptation of the monad-time library for the effectful ecosystem.++description: Adaptation of the @<https://hackage.haskell.org/package/monad-time monad-time>@ library for the @<https://hackage.haskell.org/package/effectful effectful>@ ecosystem.++extra-source-files:+ CHANGELOG.md+ README.md++tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.5 || ==9.6.2++bug-reports: https://github.com/haskell-effectful/monad-time-effectful/issues+source-repository head+ type: git+ location: https://github.com/haskell-effectful/monad-time-effectful++common language+ ghc-options: -Wall -Wcompat -Wno-unticked-promoted-constructors++ default-language: Haskell2010++ default-extensions: BangPatterns+ DataKinds+ FlexibleContexts+ GADTs+ LambdaCase+ KindSignatures+ TypeFamilies+ TypeOperators++library+ import: language++ build-depends: base <5+ , effectful-core >=1.0.0.0 && <3.0.0.0+ , monad-time+ , time++ hs-source-dirs: src+ exposed-modules: Effectful.Time
+ src/Effectful/Time.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -Wno-orphans #-}++-- | Time measurement via 'MonadTime'.+module Effectful.Time+ ( -- * Effect+ Time (..)+ , MonadTime (..)++ -- ** Handlers+ , runTime+ , runFrozenTime+ ) where++import Control.Monad.IO.Class+import Control.Monad.Time+import Data.Time+import Effectful+import Effectful.Dispatch.Dynamic+import GHC.Clock (getMonotonicTime)++-- | Provide the ability to use the 'MonadTime' instance of 'Eff'.+data Time :: Effect where+ CurrentTime :: Time m UTCTime+ MonotonicTime :: Time m Double++type instance DispatchOf Time = Dynamic++-- | Run a 'Time' effect via 'IO'.+runTime :: IOE :> es => Eff (Time : es) a -> Eff es a+runTime = interpret $ \_ -> \case+ CurrentTime -> liftIO getCurrentTime+ MonotonicTime -> liftIO getMonotonicTime++-- | Run a 'Time' effect with a frozen value of the 'CurrentTime' operation.+--+-- /Note:/ the 'MonotonicTime' operation works the same way as in 'runTime'.+runFrozenTime :: IOE :> es => UTCTime -> Eff (Time : es) a -> Eff es a+runFrozenTime time = interpret $ \_ -> \case+ CurrentTime -> pure time+ MonotonicTime -> liftIO getMonotonicTime++----------------------------------------+-- Orphan instance++instance Time :> es => MonadTime (Eff es) where+ currentTime = send CurrentTime+ monotonicTime = send MonotonicTime