napkin-1.0.0
Safe HaskellNone
LanguageGHC2021

Polysemy.Memoize

Description

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) #

Constructors

ResultCache 

Instances

Instances details
Monoid (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Semigroup (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Default (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Methods

def :: ResultCache a #

data SubCache #

Constructors

(Eq (eff m a), Ord (eff m a)) => SubCache (Map (eff m a) 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 #

Minimal complete definition

Nothing

Methods

cacheKey :: Proxy b #

default cacheKey :: Proxy b #

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 #