/
Monad.hs
36 lines (31 loc) · 960 Bytes
/
Monad.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- |
-- Module : Criterion.Monad
-- Copyright : (c) 2009 Neil Brown
--
-- License : BSD-style
-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
-- The environment in which most criterion code executes.
module Criterion.Monad
(
Criterion
, getConfig
, getConfigItem
, withConfig
) where
import Control.Monad.Reader (MonadReader, ReaderT, ask, runReaderT)
import Control.Monad.Trans (MonadIO)
import Criterion.Config (Config)
-- | The monad in which most criterion code executes.
newtype Criterion a = Criterion {
runCriterion :: ReaderT Config IO a
} deriving (Functor, Monad, MonadReader Config, MonadIO)
getConfig :: Criterion Config
getConfig = ask
getConfigItem :: (Config -> a) -> Criterion a
getConfigItem f = f `fmap` getConfig
withConfig :: Config -> Criterion a -> IO a
withConfig = flip (runReaderT . runCriterion)