Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data AtomId = forall l . AtomLike l => AtomId l
- class (Eq l, Hashable l, Typeable l) => AtomLike l where
- newtype AtomCacheT m a = AtomCacheT {}
- class Monad m => AtomCacheCtx m where
- insertATOM :: AtomLike l => l -> ATOM -> m ()
- lookupATOM :: AtomLike l => l -> m (Maybe ATOM)
- unsafeLookupATOM :: AtomLike l => l -> m ATOM
- lookupAtomId :: ATOM -> m (Maybe AtomId)
- unsafeLookupAtomId :: ATOM -> m AtomId
- type AtomName = String
- atomName :: AtomId -> AtomName
- runAtomCacheT :: Monad m => AtomCacheT m a -> m a
- seedAtoms :: (AtomLike l, Applicative m, MonadIO m) => Connection -> [l] -> AtomCacheT m a -> AtomCacheT m (Either SomeError a)
- tryLookupAtom :: (AtomLike l, AtomCacheCtx m, MonadIO m) => Connection -> l -> m (Either SomeError ATOM)
Documentation
newtype AtomCacheT m a Source
MonadTrans AtomCacheT | |
MonadError e m => MonadError e (AtomCacheT m) | |
MonadReader r m => MonadReader r (AtomCacheT m) | |
MonadState s m => MonadState s (AtomCacheT m) | |
MonadWriter w m => MonadWriter w (AtomCacheT m) | |
Monad m => Monad (AtomCacheT m) | |
Functor m => Functor (AtomCacheT m) | |
(Monad m, Functor m) => Applicative (AtomCacheT m) | |
MonadIO m => MonadIO (AtomCacheT m) | |
Monad m => AtomCacheCtx (AtomCacheT m) | |
Typeable ((* -> *) -> * -> *) AtomCacheT |
class Monad m => AtomCacheCtx m where Source
insertATOM :: AtomLike l => l -> ATOM -> m () Source
lookupATOM :: AtomLike l => l -> m (Maybe ATOM) Source
unsafeLookupATOM :: AtomLike l => l -> m ATOM Source
lookupAtomId :: ATOM -> m (Maybe AtomId) Source
unsafeLookupAtomId :: ATOM -> m AtomId Source
(AtomCacheCtx m, MonadTrans t, Monad (t m)) => AtomCacheCtx (t m) | |
Monad m => AtomCacheCtx (AtomCacheT m) |
runAtomCacheT :: Monad m => AtomCacheT m a -> m a Source
seedAtoms :: (AtomLike l, Applicative m, MonadIO m) => Connection -> [l] -> AtomCacheT m a -> AtomCacheT m (Either SomeError a) Source
Preseed the atom cache with AtomLike
s. Example:
{-# LANGUAGE DeriveDataTypeable #-} import Data.Typeable (Typeable) import Data.Hashable (Hashable(..)) import Control.Monad (forM_, void) import Control.Monad.IO.Class (liftIO) import Graphics.XHB (connect) import Graphics.XHB.AtomCache data ATOMS = NET_CLIENT_LIST | NET_NUMBER_OF_DESKTOPS deriving (Eq, Show, Typeable) instance Hashable ATOMS where hashWithSalt s = hashWithSalt s . show instance AtomLike ATOMS where toAtomName a = '_' : show a atoms :: [ATOMS] atoms = [NET_CLIENT_LIST, NET_NUMBER_OF_DESKTOPS] main :: IO () main = do Just c <- connect void $ runAtomCacheT . seedAtoms c atoms $ do forM_ atoms $ \a -> unsafeLookupATOM a >>= liftIO . print
tryLookupAtom :: (AtomLike l, AtomCacheCtx m, MonadIO m) => Connection -> l -> m (Either SomeError ATOM) Source
Lookup AtomName in cache first, if that fails, try to fetch from the X server and put it into the cache