secret
Created

  • Download Gist
gistfile1.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.