Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
data Param m k v = Param {
cacheSize :: Int
, table :: H.HashTableSTM k (Ref v)
, toIO :: forall a. m a -> IO a
, lock :: TVar Int
newtype CacheSTM m k v a = CacheSTM { runCacheSTM :: ReaderT (Param m k v) STM a }
deriving (Monad, MonadReader (Param m k v), Functor)
evalCacheSTM :: Param m k v -> CacheSTM m k v a -> IO a
evalCacheSTM p m =
atomically $ runReaderT (runCacheSTM m) p
sizedParam :: Int -> (forall a. m a -> IO a) -> IO (Param m k v)
sizedParam s f = do
ht <- H.newSized s
mv <- atomically $ newTVar 0
return $ Param s ht f mv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment