Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for effectfully memoizing other, more effectful functions.
Synopsis
- type MonadMemo s m = MonadState (MemoState s) m
- data MemoState s
- runMemo :: Monad m => s -> StateT (MemoState s) m a -> m a
- modifyMemoNonce :: MonadMemo s m => (s -> s) -> m s
- data KnotTier v d m = KnotTier {
- onKnotFound :: m d
- onKnotUsed :: d -> m v
- tieKnot :: d -> v -> m v
- unknot :: KnotTier v Void m
- memoWithKnot :: forall k v d m s. (Typeable k, Typeable v, Typeable d, Ord k, MonadMemo s m) => KnotTier v d m -> m v -> k -> m v
- 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
Documentation
type MonadMemo s m = MonadState (MemoState s) m Source #
An effectful memoization monad.
modifyMemoNonce :: MonadMemo s m => (s -> s) -> m s 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.
KnotTier | |
|
:: 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.