Safe Haskell | None |
---|---|
Language | GHC2021 |
An experimental idea to see if we can whole-sale cache the results of certain effect computations, when we can be confident that their repeated invocation should result in the same outcome. The idea is that a first interpretation of the effect stack (e.g. during a validation or dry run) can produce this memoization cache and repeated interpretations of the same effect during the same program session can just lookup results from th cache.
A good example is parsing of SQL files from disk. We'd want to do it once and have much faster resolution on repeat runs.
Documentation
newtype ResultCache (a :: EffectRow) #
Instances
Monoid (ResultCache a) # | |
Defined in Polysemy.Memoize mempty :: ResultCache a # mappend :: ResultCache a -> ResultCache a -> ResultCache a # mconcat :: [ResultCache a] -> ResultCache a # | |
Semigroup (ResultCache a) # | |
Defined in Polysemy.Memoize (<>) :: ResultCache a -> ResultCache a -> ResultCache a # sconcat :: NonEmpty (ResultCache a) -> ResultCache a # stimes :: Integral b => b -> ResultCache a -> ResultCache a # | |
Default (ResultCache a) # | |
Defined in Polysemy.Memoize def :: ResultCache a # |
insertCache :: forall {k1} {k2} eff (m :: k1) a (c :: k2). (CacheableEffect eff c, Ord (eff m a)) => eff m a -> a -> Map TypeRep SubCache -> Map TypeRep SubCache #
insertCache' :: forall {k1} {k2} eff (c :: k2) (m :: k1) a (ce :: EffectRow) (r :: EffectRow). (CacheableEffect eff c, Ord (eff m a), Member (AtomicState (ResultCache ce) :: (Type -> Type) -> Type -> Type) r) => eff m a -> a -> Sem r () #
lookupCache :: forall {k1} {k2} eff (m :: k1) a (c :: k2). (CacheableEffect eff c, Ord (eff m a)) => eff m a -> Map TypeRep SubCache -> Maybe a #
lookupCache' :: forall {k1} {k2} eff (c :: k2) (m :: k1) a (ce :: EffectRow) (r :: EffectRow). (CacheableEffect eff c, Ord (eff m a), Member (AtomicState (ResultCache ce) :: (Type -> Type) -> Type -> Type) r) => eff m a -> Sem r (Maybe a) #
class Typeable (Proxy b) => CacheableEffect (a :: k) (b :: k1) | a -> b where #
Nothing
Instances
CacheableEffect (LoadQuery :: k -> Type -> Type) LoadQueryCacheKey # | |
Defined in Napkin.Run.Effects.Languages.LoadQuery | |
CacheableEffect (SqlParse :: k -> Type -> Type) SqlParseCacheKey # | |
Defined in Napkin.Run.Effects.Languages.SqlParse | |
CacheableEffect (SqlRender :: k -> Type -> Type) SqlRenderCacheKey # | |
Defined in Napkin.Run.Effects.Languages.SqlRender |
cacheEffect :: forall {k} e (r :: EffectRow) (rInitial :: EffectRow) (m :: Type -> Type) a (c :: k) (ce :: EffectRow). (Ord (e m a), Member e r, Member (AtomicState (ResultCache ce) :: (Type -> Type) -> Type -> Type) r, CacheableEffect e c, m ~ Sem rInitial, Coercible (e (Sem rInitial) a) (e (Sem r) a), Member e ce) => e (Sem rInitial) a -> Tactical e (Sem rInitial) r a #