Safe Haskell | None |
---|---|
Language | GHC2021 |
Control.Monad.Credit
Synopsis
- class Monad m => MonadCount (m :: Type -> Type) where
- tick :: m ()
- class Monad m => MonadLazy (m :: Type -> Type) where
- class HasStep (t :: k -> Type) (m :: k -> Type) where
- step :: forall (a :: k). t a -> m a
- newtype Lazy (m :: k -> Type) (a :: k) = Lazy (m a)
- data Ticks
- data Credit
- class (MonadCount m, MonadLazy m, MonadFail m) => MonadCredit (m :: Type -> Type) where
- creditWith :: forall (t :: Type -> Type) a. Thunk m t a -> Credit -> m ()
- hasAtLeast :: forall (t :: Type -> Type) a. Thunk m t a -> Credit -> m ()
- class MonadCredit m => MonadInherit (m :: Type -> Type) where
- creditAllTo :: forall (t :: Type -> Type) a. Thunk m t a -> m ()
- type CounterM s = CounterT s Identity
- runCounterM :: (forall s. CounterM s a) -> Either String (a, Ticks)
- data CounterT s (m :: Type -> Type) a
- runCounterT :: Monad m => (forall s. CounterT s m a) -> m (Either String (a, Ticks))
- type CreditM s = CreditT s Identity
- runCreditM :: Credit -> (forall s. CreditM s a) -> Either Error a
- data CreditT s (m :: Type -> Type) a
- runCreditT :: Monad m => Credit -> (forall s. CreditT s m a) -> m (Either Error a)
- data Error
- data Cell
- data Memory
- mkMCell :: String -> [Memory] -> Memory
- mkMList :: [Memory] -> Maybe Memory -> Memory
- linearize :: Memory -> Memory
- class Monad m => MemoryCell (m :: Type -> Type) a where
- prettyCell :: a -> m Memory
- class Monad m => MonadMemory (m :: Type -> Type) where
- prettyThunk :: forall a (t :: Type -> Type). (MemoryCell m a, MemoryCell m (t a)) => Thunk m t a -> m Memory
- newtype PrettyCell a = PrettyCell a
- class MemoryStructure (t :: (Type -> Type) -> Type) where
- prettyStructure :: MonadMemory m => t m -> m Memory
Computations with credits
class Monad m => MonadCount (m :: Type -> Type) where Source #
Instances
Monad m => MonadCount (CounterT s m) Source # | |
Defined in Control.Monad.Credit.CounterM | |
Monad m => MonadCount (CreditT s m) Source # | |
Defined in Control.Monad.Credit.CreditM |
class Monad m => MonadLazy (m :: Type -> Type) where Source #
Methods
delay :: t a -> m (Thunk m t a) Source #
delay creates a new cell with the given thunk
force :: forall (t :: Type -> Type) a. HasStep t m => Thunk m t a -> m a Source #
force retrieves and evaluates the thunk of a cell
lazymatch :: Thunk m t a -> (a -> m b) -> (t a -> m b) -> m b Source #
lazymatch can inspect the unevaluated thunk and allows us to perform an action like forcing or assigning credits.
Instances
Monad m => MonadLazy (CounterT s m) Source # | |
Defined in Control.Monad.Credit.CounterM Methods delay :: t a -> CounterT s m (Thunk (CounterT s m) t a) Source # force :: forall (t :: Type -> Type) a. HasStep t (CounterT s m) => Thunk (CounterT s m) t a -> CounterT s m a Source # lazymatch :: Thunk (CounterT s m) t a -> (a -> CounterT s m b) -> (t a -> CounterT s m b) -> CounterT s m b Source # | |
Monad m => MonadLazy (CreditT s m) Source # | |
Defined in Control.Monad.Credit.CreditM |
class HasStep (t :: k -> Type) (m :: k -> Type) where Source #
Thunks can take a step to yield a computation that evaluates to their result.
Instances
newtype Lazy (m :: k -> Type) (a :: k) Source #
A basic thunk that contains the computation to be evaluated. This type can be used to express any thunk but its disadvantage is that it will be printed merely as "lazy".
Constructors
Lazy (m a) |
Instances
Enum Ticks Source # | |
Defined in Control.Monad.Credit.Base | |
Num Ticks Source # | |
Integral Ticks Source # | |
Real Ticks Source # | |
Defined in Control.Monad.Credit.Base Methods toRational :: Ticks -> Rational # | |
Show Ticks Source # | |
Eq Ticks Source # | |
Ord Ticks Source # | |
Pretty Ticks Source # | |
Defined in Control.Monad.Credit.Base |
Instances
Enum Credit Source # | |
Defined in Control.Monad.Credit.Base | |
Num Credit Source # | |
Integral Credit Source # | |
Defined in Control.Monad.Credit.Base | |
Real Credit Source # | |
Defined in Control.Monad.Credit.Base Methods toRational :: Credit -> Rational # | |
Show Credit Source # | |
Eq Credit Source # | |
Ord Credit Source # | |
Pretty Credit Source # | |
Defined in Control.Monad.Credit.Base |
class (MonadCount m, MonadLazy m, MonadFail m) => MonadCredit (m :: Type -> Type) where Source #
A computation in the credit monad has a given amounts of credits, which it can spend on computation or transfer to other cells.
Methods
creditWith :: forall (t :: Type -> Type) a. Thunk m t a -> Credit -> m () Source #
creditWith transfers a given amount of credits to a cell
hasAtLeast :: forall (t :: Type -> Type) a. Thunk m t a -> Credit -> m () Source #
assert that a cell has at least a given amount of credits
Instances
Monad m => MonadCredit (CounterT s m) Source # | |
Monad m => MonadCredit (CreditT s m) Source # | |
class MonadCredit m => MonadInherit (m :: Type -> Type) where Source #
Methods
creditAllTo :: forall (t :: Type -> Type) a. Thunk m t a -> m () Source #
creditAllTo transfers all credits to a cell and assigns it as heir
Instances
Monad m => MonadInherit (CounterT s m) Source # | |
Defined in Control.Monad.Credit.CounterM | |
Monad m => MonadInherit (CreditT s m) Source # | |
Defined in Control.Monad.Credit.CreditM |
Counter Monad
type CounterM s = CounterT s Identity Source #
An instance of the counter monad using ST to memoize thunks.
data CounterT s (m :: Type -> Type) a Source #
A monad transformer on the counter monad. Warning! This monad transformer includes the ST monad transformer and should not be used with monads that can contain multiple answers, like the list monad. Safe monads include the monads State, Reader, Writer, Maybe and combinations of their corresponding monad transformers.
Instances
Credit Monad
type CreditM s = CreditT s Identity Source #
An instance of the credit monad using ST to memoize thunks.
data CreditT s (m :: Type -> Type) a Source #
A monad transformer on the credit monad. Warning! This monad transformer includes the ST monad transformer and should not be used with monads that can contain multiple answers, like the list monad. Safe monads include the monads State, Reader, Writer, Maybe and combinations of their corresponding monad transformers.
Instances
Constructors
OutOfCredits Cell | |
InvalidAccount Cell | |
InvalidTick Cell | |
ClosedCurrent Cell | |
UserError String | |
AssertionFailed Cell Credit Credit |
Instances
Show Error Source # | |
Eq Error Source # | |
Ord Error Source # | |
Pretty Error Source # | |
Defined in Control.Monad.Credit.CreditM | |
Monad m => MonadError Error (CreditT s m) Source # | |
Defined in Control.Monad.Credit.CreditM Methods throwError :: Error -> CreditT s m a # catchError :: CreditT s m a -> (Error -> CreditT s m a) -> CreditT s m a # | |
Pretty a => Pretty (Either Error a) Source # | |
Pretty-printing memory cells
A view of memory that can be pretty-printed.
mkMCell :: String -> [Memory] -> Memory Source #
Make memory cell with a given tag and a list of children.
mkMList :: [Memory] -> Maybe Memory -> Memory Source #
A special case for nicer printing of list-like datatypes. ''mkMList [m1,...,mn] Nothing'' renders as ''[m1, .., mn]'', while ''mkMList [m1,...,mn] (Just m)'' renders as ''[m1, .., mn] ++ m''.
linearize :: Memory -> Memory Source #
Inline memory cells that are only used once and remove them from the store
class Monad m => MemoryCell (m :: Type -> Type) a where Source #
A class for pretty-printing memory cells.
Methods
prettyCell :: a -> m Memory Source #
Instances
class Monad m => MonadMemory (m :: Type -> Type) where Source #
Methods
prettyThunk :: forall a (t :: Type -> Type). (MemoryCell m a, MemoryCell m (t a)) => Thunk m t a -> m Memory Source #
Instances
Monad m => MonadMemory (CreditT s m) Source # | |
Defined in Control.Monad.Credit.CreditM Methods prettyThunk :: forall a (t :: Type -> Type). (MemoryCell (CreditT s m) a, MemoryCell (CreditT s m) (t a)) => Thunk (CreditT s m) t a -> CreditT s m Memory Source # |
newtype PrettyCell a Source #
Constructors
PrettyCell a |
Instances
class MemoryStructure (t :: (Type -> Type) -> Type) where Source #
Methods
prettyStructure :: MonadMemory m => t m -> m Memory Source #