Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Monad m => MonadMemoize m where
- memoize :: (MonadMemoize m, Ord a, Typeable a, Typeable p) => Name -> (a -> m p) -> a -> m p
- newtype MemoizeT m a = MemoizeT {
- unMemoizeT :: StateT (DMap MemoizationKey Identity) m a
- runMemoizeT :: forall m a. Monad m => MemoizeT m a -> m a
- data MemoizationKey (t :: Type) where
- MemoizationKey :: (Ord a, Typeable a, Typeable p) => Name -> a -> MemoizationKey p
Documentation
class Monad m => MonadMemoize m where Source #
:: forall a p. (Ord a, Typeable a, Typeable p) | |
=> Name | A unique name used to identify the function being memoized. There isn’t
really any metaprogramming going on here, we just use a Template Haskell
|
-> a | The value to use as the memoization key. It’s the caller’s responsibility to ensure multiple calls to the same function don’t use the same key. |
-> m p | |
-> m p |
Memoizes a parser constructor function for the extent of a single schema construction process. This is mostly useful for recursive parsers; see Note [Tying the knot] for more details.
The generality of the type here allows us to use this with multiple concrete parser types:
memoizeOn
:: (MonadMemoize
m, MonadParse n) =>Name
-> a -> m (Parser n b) -> m (Parser n b)memoizeOn
:: (MonadMemoize
m, MonadParse n) =>Name
-> a -> m (FieldParser n b) -> m (FieldParser n b)
Instances
MonadIO m => MonadMemoize (MemoizeT m) Source # | see Note [MemoizeT requires MonadIO] |
MonadMemoize m => MonadMemoize (ReaderT a m) Source # | |
memoize :: (MonadMemoize m, Ord a, Typeable a, Typeable p) => Name -> (a -> m p) -> a -> m p Source #
A wrapper around memoizeOn
that memoizes a function by using its argument
as the key.
MemoizeT | |
|
Instances
MonadReader r m => MonadReader r (MemoizeT m) Source # | |
MonadError e m => MonadError e (MemoizeT m) Source # | |
Defined in Control.Monad.Memoize throwError :: e -> MemoizeT m a # catchError :: MemoizeT m a -> (e -> MemoizeT m a) -> MemoizeT m a # | |
Monad m => Monad (MemoizeT m) Source # | |
Functor m => Functor (MemoizeT m) Source # | |
Monad m => Applicative (MemoizeT m) Source # | |
Defined in Control.Monad.Memoize | |
MonadIO m => MonadMemoize (MemoizeT m) Source # | see Note [MemoizeT requires MonadIO] |
runMemoizeT :: forall m a. Monad m => MemoizeT m a -> m a Source #
data MemoizationKey (t :: Type) where Source #
A key used to distinguish calls to memoize
d functions. The Name
distinguishes calls to completely different parsers, and the a
value
records the arguments.
MemoizationKey :: (Ord a, Typeable a, Typeable p) => Name -> a -> MemoizationKey p |