Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains basic examples advices.
BEWARE! These are provided for illustrative purposes only, they strive for simplicity and not robustness or efficiency.
Synopsis
- returnMempty :: forall ca m r. (Monad m, Monoid r) => Advice ca m r
- printArgs :: forall m r. MonadIO m => Handle -> String -> Advice Show m r
- data AnyEq where
- doCachingBadly :: forall m r. Monad m => (AnyEq -> m (Maybe r)) -> (AnyEq -> r -> m ()) -> Advice (Eq `And` Typeable) m r
- doAsyncBadly :: forall ca m. MonadUnliftIO m => Advice ca m ()
Basic advices
returnMempty :: forall ca m r. (Monad m, Monoid r) => Advice ca m r Source #
Makes functions discard their result and always return mempty
.
A helper datatype for universal equality comparisons of existentialized values, used by doCachingBadly
.
For a more complete elaboration of this idea, see the the "exinst" package.
doCachingBadly :: forall m r. Monad m => (AnyEq -> m (Maybe r)) -> (AnyEq -> r -> m ()) -> Advice (Eq `And` Typeable) m r Source #
Given the means for looking up and storing r
values in the underlying
monad m
, makes functions (inefficiently) cache their results.
The monad m
and the result type r
must be known before building the
advice. So, once built, this Advice
won't be polymorphic over them.
The implementation of this function makes use of the existential type
parameter u
of makeAdvice
, because the phase that processes the function
arguments needs to communicate the calculated AnyEq
cache key to the phase
that processes the function result.
A better implementation of this advice would likely use an AnyHashable
helper datatype for the keys.
doAsyncBadly :: forall ca m. MonadUnliftIO m => Advice ca m () Source #
Makes functions that return ()
launch asynchronously.
A better implementation of this advice would likely use the "async"
package instead of bare forkIO
.
The IO
monad could be generalized to MonadUnliftIO
.