compaREST-0.1.0.1: Compatibility checker for OpenAPI
Safe HaskellNone
LanguageHaskell2010

Data.OpenApi.Compare.Memo

Description

Utilities for effectfully memoizing other, more effectful functions.

Synopsis

Documentation

type MonadMemo s m = MonadState (MemoState s) m Source #

An effectful memoization monad.

data MemoState s Source #

Instances

Instances details
MonadState (MemoState VarRef) CompatM Source # 
Instance details

Defined in Data.OpenApi.Compare.Subtree

runMemo :: Monad m => s -> StateT (MemoState s) m a -> m a Source #

Run a memoized computation.

modifyMemoNonce :: MonadMemo s m => (s -> s) -> m s Source #

data KnotTier v d m Source #

A description of how to effectfully tie knots in type v, using the m monad, and by sharing some d data among the recursive instances.

Constructors

KnotTier 

Fields

  • onKnotFound :: m d

    Create some data that will be connected to this knot

  • onKnotUsed :: d -> m v

    This is what the knot will look like as a value to the inner computations

  • tieKnot :: d -> v -> m v

    Once we're done and we're outside, tie the knot using the datum

memoWithKnot Source #

Arguments

:: forall k v d m s. (Typeable k, Typeable v, Typeable d, Ord k, MonadMemo s m) 
=> KnotTier v d m 
-> m v

the computation to memoize

-> k

key for memoization

-> m v 

Run a potentially recursive computation. The provided key will be used to refer to the result of this computation. If during the computation, another attempt to run the computation with the same key is made, we run a tying-the-knot procedure.

If another attempt to run the computation with the same key is made *after we're done*, we will return the memoized value.

memoTaggedWithKnot :: forall t k v d m s. (Typeable t, Typeable k, Typeable v, Typeable d, Ord k, MonadMemo s m) => KnotTier v d m -> m v -> k -> m v Source #

Disambiguate memoized computations with an arbitrary tag.