napkin-0.5.13
Safe HaskellNone
LanguageHaskell2010

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
Semigroup (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Monoid (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Default (ResultCache a) # 
Instance details

Defined in Polysemy.Memoize

Methods

def :: ResultCache a #

data SubCache #

Constructors

forall eff m a.(Eq (eff m a), Ord (eff m a)) => SubCache (Map (eff m a) a) 

insertCache :: forall eff m a c. (CachableEffect eff c, Ord (eff m a), Eq (eff m a)) => eff m a -> a -> Map TypeRep SubCache -> Map TypeRep SubCache #

insertCache' :: (CachableEffect eff c, Ord (eff m a), Eq (eff m a), Member (AtomicState (ResultCache ce)) r, Member eff ce) => eff m a -> a -> Sem r () #

lookupCache :: forall eff m a c. (CachableEffect eff c, Ord (eff m a), Eq (eff m a)) => eff m a -> Map TypeRep SubCache -> Maybe a #

lookupCache' :: (CachableEffect eff c, Ord (eff m a), Eq (eff m a), Member (AtomicState (ResultCache ce)) r, Member eff ce) => eff m a -> Sem r (Maybe a) #

class Typeable (Proxy b) => CachableEffect a b | a -> b where #

Minimal complete definition

Nothing

Methods

cacheKey :: Proxy b #

default cacheKey :: Proxy b #

cacheEffect :: forall (e :: Effect) r rInitial m a c ce. (Eq (e m a), Ord (e m a), Member e r, Member (AtomicState (ResultCache ce)) r, CachableEffect 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 #