Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type FreerT f = FreeT (Ap f)
- type Fraxl r = FreerT (Union r)
- type Fetch f m a = ASeq f a -> m (ASeq m a)
- runFraxl :: Monad m => (forall a'. Fetch f m a') -> FreerT f m a -> m a
- simpleAsyncFetch :: MonadIO m => (forall x. f x -> IO x) -> Fetch f m a
- fetchNil :: Applicative m => Fetch (Union `[]`) m a
- (|:|) :: forall f r a m. Monad m => (forall a'. Fetch f m a') -> (forall a'. Fetch (Union r) m a') -> Fetch (Union (f : r)) m a
- data ASeq f a where
- reduceASeq :: Applicative f => ASeq f u -> f u
- hoistASeq :: (forall x. f x -> g x) -> ASeq f a -> ASeq g a
- traverseASeq :: Applicative h => (forall x. f x -> h (g x)) -> ASeq f a -> h (ASeq g a)
- rebaseASeq :: ASeq f u -> (forall x. (x -> y) -> ASeq f x -> z) -> (v -> u -> y) -> ASeq f v -> z
- newtype CachedFetch f a = CachedFetch (f a)
- fetchCached :: forall t m f a. (Monad m, MonadTrans t, MonadState (DMap f MVar) (t m), GCompare f, MonadIO (t m)) => (forall a'. Fetch f m a') -> Fetch (CachedFetch f) (t m) a
- runCachedFraxl :: forall m f a. (MonadIO m, GCompare f) => (forall a'. Fetch f m a') -> FreerT f m a -> DMap f MVar -> m (a, DMap f MVar)
- evalCachedFraxl :: forall m f a. (MonadIO m, GCompare f) => (forall a'. Fetch f m a') -> FreerT f m a -> m a
- module Data.GADT.Compare
- class Monad m => MonadFraxl f m where
- dataFetch :: f a -> m a
The Fraxl Monad
type FreerT f = FreeT (Ap f) Source
Fraxl is based on a particular Freer monad. This Freer monad has applicative optimization, which is used to parallelize effects.
type Fetch f m a = ASeq f a -> m (ASeq m a) Source
A data source is an effect f
that operates in some monad m
.
Given a sequence of effects,
a data source should use m
to prepare a corresponding sequence of results.
simpleAsyncFetch :: MonadIO m => (forall x. f x -> IO x) -> Fetch f m a Source
fetchNil :: Applicative m => Fetch (Union `[]`) m a Source
Fetch empty union.
Only necessary to terminate a list of Fetch
functions for Fetch (Union r)
(|:|) :: forall f r a m. Monad m => (forall a'. Fetch f m a') -> (forall a'. Fetch (Union r) m a') -> Fetch (Union (f : r)) m a infixr 5 Source
Like '(:)' for constructing Fetch (Union (f ': r))
The Sequence of Effects
reduceASeq :: Applicative f => ASeq f u -> f u Source
reduceASeq a sequence of applicative effects into an applicative.
hoistASeq :: (forall x. f x -> g x) -> ASeq f a -> ASeq g a Source
Transform a sequence of f
into a sequence of g
.
traverseASeq :: Applicative h => (forall x. f x -> h (g x)) -> ASeq f a -> h (ASeq g a) Source
Traverse a sequence with resepect to its interpretation type f
.
rebaseASeq :: ASeq f u -> (forall x. (x -> y) -> ASeq f x -> z) -> (v -> u -> y) -> ASeq f v -> z Source
It may not look like it, but this appends two sequences. See Dave Menendez's work for more explanation.
Caching
newtype CachedFetch f a Source
Caching in Fraxl works by translating FreerT f
into
FreerT (CachedFetch f)
, then running with CachedFetch'
s DataSource.
That instance requires f
to to have a GCompare
instance.
The CachedFetch
instance uses a MonadState
to track cached requests.
The state variable is a DMap
from the 'dependent-map' package.
Keys are requests, and values are MVar
s of the results.
CachedFetch (f a) |
fetchCached :: forall t m f a. (Monad m, MonadTrans t, MonadState (DMap f MVar) (t m), GCompare f, MonadIO (t m)) => (forall a'. Fetch f m a') -> Fetch (CachedFetch f) (t m) a Source
runCachedFraxl :: forall m f a. (MonadIO m, GCompare f) => (forall a'. Fetch f m a') -> FreerT f m a -> DMap f MVar -> m (a, DMap f MVar) Source
Runs a Fraxl computation with caching using a given starting cache. Alongside the result, it returns the final cache.
evalCachedFraxl :: forall m f a. (MonadIO m, GCompare f) => (forall a'. Fetch f m a') -> FreerT f m a -> m a Source
Like runCachedFraxl
, except it starts with an empty cache
and discards the final cache.
module Data.GADT.Compare
Fraxl Monads
class Monad m => MonadFraxl f m where Source
Class for Fraxl-capable monads.
Nothing
MonadFraxl f m => MonadFraxl f (MaybeT m) Source | |
MonadFraxl f m => MonadFraxl f (ListT m) Source | |
MonadFraxl f m => MonadFraxl f (IdentityT m) Source | |
(MonadFraxl f m, Monoid w) => MonadFraxl f (WriterT w m) Source | |
(MonadFraxl f m, Monoid w) => MonadFraxl f (WriterT w m) Source | |
MonadFraxl f m => MonadFraxl f (StateT s m) Source | |
MonadFraxl f m => MonadFraxl f (StateT s m) Source | |
MonadFraxl f m => MonadFraxl f (ReaderT e m) Source | |
MonadFraxl f m => MonadFraxl f (ExceptT e m) Source | |
MonadFraxl f m => MonadFraxl f (ContT r m) Source | |
Monad m => MonadFraxl f (FreerT f m) Source | |
(Monad m, (∈) (* -> *) f r) => MonadFraxl f (Fraxl r m) Source | |
(MonadFraxl f m, Monoid w) => MonadFraxl f (RWST r w s m) Source | |
(MonadFraxl f m, Monoid w) => MonadFraxl f (RWST r w s m) Source |