Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype ReaderSoup_ (record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) ctxs a = ReaderSoup {
- unReaderSoup :: ReaderT (record ElField ctxs) IO a
- type IsInSoup_ r ctxs l = (HasField r l ctxs ctxs (ContextFromName l) (ContextFromName l), RecElemFCtx r ElField)
- type IsInSoup ctxs l = IsInSoup_ ARec ctxs l
- class NatToInt (RLength (ContextsFromArgs args)) => ArgsForSoupConsumption args where
- type ContextsFromArgs args :: [(Symbol, *)]
- consumeSoup_ :: Rec ElField args -> CookedReaderSoup (ContextsFromArgs args) a -> IO a
- newtype ContextRunner t m = ContextRunner {
- runContext :: forall r. t m r -> m r
- data Label (a :: Symbol)
- (=:) :: KnownSymbol l => Label l -> v -> ElField (l ::: v)
- type (:::) (a :: k) (b :: k1) = (,) a b
- data Rec (a :: u -> Type) (b :: [u]) :: forall u. (u -> Type) -> [u] -> Type where
- consumeSoup :: ArgsForSoupConsumption args => Rec ElField args -> ReaderSoup (ContextsFromArgs args) a -> IO a
- type Reader r = ReaderT r Identity
- newtype ReaderT r (m :: k -> Type) (a :: k) :: forall k. Type -> (k -> Type) -> k -> Type = ReaderT {
- runReaderT :: r -> m a
- runReader :: Reader r a -> r -> a
- mapReader :: (a -> b) -> Reader r a -> Reader r b
- withReader :: (r' -> r) -> Reader r a -> Reader r' a
- mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b
- withReaderT :: (r' -> r) -> ReaderT r m a -> ReaderT r' m a
- liftCatch :: Catch e m a -> Catch e (ReaderT r m) a
- liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b
- asks :: Monad m => (r -> a) -> ReaderT r m a
- hoist :: (MFunctor t, Monad m) => (forall a. m a -> n a) -> t m b -> t n b
- class Monad m => MonadReader r (m :: Type -> Type) | m -> r where
- type ReaderSoup = ReaderSoup_ ARec
- type family ContextFromName (l :: Symbol) :: *
- class SoupContext c t | c -> t where
- type CanBeScoopedIn_ r t ctxs l = (IsInSoup_ r ctxs l, KnownSymbol l, SoupContext (ContextFromName l) t)
- type CanBeScoopedIn t ctxs l = CanBeScoopedIn_ ARec t ctxs l
- type CanRunSoupContext l t = SoupContext (ContextFromName l) t
- askSoup :: IsInSoup_ r ctxs l => Label l -> ReaderSoup_ r ctxs (ContextFromName l)
- filtering :: RecSubset ARec ctxs' ctxs (RImage ctxs' ctxs) => ReaderSoup ctxs' a -> ReaderSoup ctxs a
- picking :: CanBeScoopedIn_ r t ctxs l => Label l -> t IO a -> ReaderSoup_ r ctxs a
- scooping :: CanBeScoopedIn_ r t ctxs l => Label l -> t (ReaderSoup_ r ctxs) a -> ReaderSoup_ r ctxs a
- pouring :: forall l ctxs t a r. CanBeScoopedIn_ r t ctxs l => Label l -> ReaderSoup_ r ctxs a -> t (ReaderSoup_ r ctxs) a
- data ElField (field :: (Symbol, Type)) where
- type Spoon = Spoon_ ARec
- type CookedReaderSoup = ReaderSoup_ Rec
- cookReaderSoup :: NatToInt (RLength ctxs) => ReaderSoup ctxs a -> CookedReaderSoup ctxs a
- pickTopping :: KnownSymbol l => CookedReaderSoup ((l ::: c) ': ctxs) a -> ReaderT c (CookedReaderSoup ctxs) a
- eatTopping :: KnownSymbol l => CookedReaderSoup ((l ::: c) ': ctxs) a -> c -> CookedReaderSoup ctxs a
- finishBroth :: CookedReaderSoup '[] a -> IO a
- rioToSpoon :: forall l ctxs a r. IsInSoup_ r ctxs l => ReaderT (ContextFromName l) IO a -> Spoon_ r ctxs l a
- spoonToReaderT :: forall l ctxs a r. (IsInSoup_ r ctxs l, KnownSymbol l) => Spoon_ r ctxs l a -> ReaderT (ContextFromName l) (ReaderSoup_ r ctxs) a
- dipping :: Label l -> Spoon_ r ctxs l a -> ReaderSoup_ r ctxs a
- withSpoon :: forall l ctxs t a r. CanBeScoopedIn_ r t ctxs l => t (ReaderSoup_ r ctxs) a -> Spoon_ r ctxs l a
- fromLabel :: IsLabel x a => a
API for running a ReaderSoup
newtype ReaderSoup_ (record :: ((Symbol, *) -> *) -> [(Symbol, *)] -> *) ctxs a Source #
Represents a set of Reader-like monads as a one-layer Reader that can grow and host more Readers, in a way that's more generic than creating you own application stack of Reader and implementing a host of MonadXXX classes, because each of these MonadXXX classes can be implemented once and for all for the ReaderSoup type.
ReaderSoup | |
|
Instances
type IsInSoup_ r ctxs l = (HasField r l ctxs ctxs (ContextFromName l) (ContextFromName l), RecElemFCtx r ElField) Source #
class NatToInt (RLength (ContextsFromArgs args)) => ArgsForSoupConsumption args where Source #
type ContextsFromArgs args :: [(Symbol, *)] Source #
consumeSoup_ :: Rec ElField args -> CookedReaderSoup (ContextsFromArgs args) a -> IO a Source #
Instances
ArgsForSoupConsumption ([] :: [(Symbol, Type)]) Source # | |
Defined in Control.Monad.ReaderSoup type ContextsFromArgs [] :: [(Symbol, Type)] Source # consumeSoup_ :: Rec ElField [] -> CookedReaderSoup (ContextsFromArgs []) a -> IO a Source # | |
(ArgsForSoupConsumption restArgs, m ~ CookedReaderSoup (ContextsFromArgs restArgs), CanRunSoupContext l t) => ArgsForSoupConsumption ((l ::: ContextRunner t m) ': restArgs) Source # | |
Defined in Control.Monad.ReaderSoup type ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs) :: [(Symbol, Type)] Source # consumeSoup_ :: Rec ElField ((l ::: ContextRunner t m) ': restArgs) -> CookedReaderSoup (ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs)) a -> IO a Source # |
newtype ContextRunner t m Source #
Knowing the prefered monad to run some context, gives you a way to override this monad's runner.
ContextRunner | |
|
Instances
(ArgsForSoupConsumption restArgs, m ~ CookedReaderSoup (ContextsFromArgs restArgs), CanRunSoupContext l t) => ArgsForSoupConsumption ((l ::: ContextRunner t m) ': restArgs) Source # | |
Defined in Control.Monad.ReaderSoup type ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs) :: [(Symbol, Type)] Source # consumeSoup_ :: Rec ElField ((l ::: ContextRunner t m) ': restArgs) -> CookedReaderSoup (ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs)) a -> IO a Source # | |
type ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs) Source # | |
Defined in Control.Monad.ReaderSoup type ContextsFromArgs ((l ::: ContextRunner t m) ': restArgs) = (l ::: ContextFromName l) ': ContextsFromArgs restArgs |
Proxy for label type
(=:) :: KnownSymbol l => Label l -> v -> ElField (l ::: v) infix 8 #
Operator for creating an ElField
. With the -XOverloadedLabels
extension, this permits usage such as, #foo =: 23
to produce a
value of type ElField ("foo" ::: Int)
.
data Rec (a :: u -> Type) (b :: [u]) :: forall u. (u -> Type) -> [u] -> Type where #
A record is parameterized by a universe u
, an interpretation f
and a
list of rows rs
. The labels or indices of the record are given by
inhabitants of the kind u
; the type of values at any label r :: u
is
given by its interpretation f r :: *
.
RNil :: forall u (a :: u -> Type) (b :: [u]). Rec a ([] :: [u]) | |
(:&) :: forall u (a :: u -> Type) (b :: [u]) (r :: u) (rs :: [u]). !(a r) -> !(Rec a rs) -> Rec a (r ': rs) infixr 7 |
Instances
RecSubset (Rec :: (k -> Type) -> [k] -> Type) ([] :: [k]) (ss :: [k]) ([] :: [Nat]) | |
Defined in Data.Vinyl.Lens type RecSubsetFCtx Rec f :: Constraint # | |
(RElem r ss i, RSubset rs ss is) => RecSubset (Rec :: (k -> Type) -> [k] -> Type) (r ': rs :: [k]) (ss :: [k]) (i ': is) | |
Defined in Data.Vinyl.Lens type RecSubsetFCtx Rec f :: Constraint # | |
RecElem (Rec :: (a -> Type) -> [a] -> Type) (r :: a) (r' :: a) (r ': rs :: [a]) (r' ': rs :: [a]) Z | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f :: Constraint # | |
(RIndex r (s ': rs) ~ S i, RecElem (Rec :: (a -> Type) -> [a] -> Type) r r' rs rs' i) => RecElem (Rec :: (a -> Type) -> [a] -> Type) (r :: a) (r' :: a) (s ': rs :: [a]) (s ': rs' :: [a]) (S i) | |
Defined in Data.Vinyl.Lens type RecElemFCtx Rec f :: Constraint # | |
TestCoercion f => TestCoercion (Rec f :: [u] -> Type) | |
Defined in Data.Vinyl.Core | |
TestEquality f => TestEquality (Rec f :: [u] -> Type) | |
Defined in Data.Vinyl.Core | |
Eq (Rec f ([] :: [u])) | |
(Eq (f r), Eq (Rec f rs)) => Eq (Rec f (r ': rs)) | |
Ord (Rec f ([] :: [u])) | |
Defined in Data.Vinyl.Core | |
(Ord (f r), Ord (Rec f rs)) => Ord (Rec f (r ': rs)) | |
Defined in Data.Vinyl.Core compare :: Rec f (r ': rs) -> Rec f (r ': rs) -> Ordering # (<) :: Rec f (r ': rs) -> Rec f (r ': rs) -> Bool # (<=) :: Rec f (r ': rs) -> Rec f (r ': rs) -> Bool # (>) :: Rec f (r ': rs) -> Rec f (r ': rs) -> Bool # (>=) :: Rec f (r ': rs) -> Rec f (r ': rs) -> Bool # max :: Rec f (r ': rs) -> Rec f (r ': rs) -> Rec f (r ': rs) # min :: Rec f (r ': rs) -> Rec f (r ': rs) -> Rec f (r ': rs) # | |
(RMap rs, ReifyConstraint Show f rs, RecordToList rs) => Show (Rec f rs) | Records may be shown insofar as their points may be shown.
|
Generic (Rec f ([] :: [u])) | |
Generic (Rec f rs) => Generic (Rec f (r ': rs)) | |
Semigroup (Rec f ([] :: [u])) | |
(Semigroup (f r), Semigroup (Rec f rs)) => Semigroup (Rec f (r ': rs)) | |
Monoid (Rec f ([] :: [u])) | |
(Monoid (f r), Monoid (Rec f rs)) => Monoid (Rec f (r ': rs)) | |
Storable (Rec f ([] :: [u])) | |
Defined in Data.Vinyl.Core | |
(Storable (f r), Storable (Rec f rs)) => Storable (Rec f (r ': rs)) | |
Defined in Data.Vinyl.Core sizeOf :: Rec f (r ': rs) -> Int # alignment :: Rec f (r ': rs) -> Int # peekElemOff :: Ptr (Rec f (r ': rs)) -> Int -> IO (Rec f (r ': rs)) # pokeElemOff :: Ptr (Rec f (r ': rs)) -> Int -> Rec f (r ': rs) -> IO () # peekByteOff :: Ptr b -> Int -> IO (Rec f (r ': rs)) # pokeByteOff :: Ptr b -> Int -> Rec f (r ': rs) -> IO () # | |
type RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) (f :: k -> Type) | |
Defined in Data.Vinyl.Lens | |
type RecSubsetFCtx (Rec :: (k -> Type) -> [k] -> Type) (f :: k -> Type) | |
Defined in Data.Vinyl.Lens | |
type RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) | |
Defined in Data.Vinyl.Lens | |
type RecElemFCtx (Rec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) | |
Defined in Data.Vinyl.Lens | |
type Rep (Rec f (r ': rs)) | |
Defined in Data.Vinyl.Core type Rep (Rec f (r ': rs)) = C1 (MetaCons ":&" (InfixI RightAssociative 7) False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 (f r)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rep (Rec f rs))) | |
type Rep (Rec f ([] :: [u])) | |
Defined in Data.Vinyl.Core |
consumeSoup :: ArgsForSoupConsumption args => Rec ElField args -> ReaderSoup (ContextsFromArgs args) a -> IO a Source #
From the list of the arguments to initialize the contexts, runs the whole
ReaderSoup_
API for working in a ReaderSoup and creating instances of SoupContext
type Reader r = ReaderT r Identity #
The parameterizable reader monad.
Computations are functions of a shared environment.
The return
function ignores the environment, while >>=
passes
the inherited environment to both subcomputations.
newtype ReaderT r (m :: k -> Type) (a :: k) :: forall k. Type -> (k -> Type) -> k -> Type #
The reader monad transformer, which adds a read-only environment to the given monad.
The return
function ignores the environment, while >>=
passes
the inherited environment to both subcomputations.
ReaderT | |
|
Instances
:: Reader r a | A |
-> r | An initial environment. |
-> a |
Runs a Reader
and extracts the final value from it.
(The inverse of reader
.)
:: (r' -> r) | The function to modify the environment. |
-> Reader r a | Computation to run in the modified environment. |
-> Reader r' a |
Execute a computation in a modified environment
(a specialization of withReaderT
).
runReader
(withReader
f m) =runReader
m . f
mapReaderT :: (m a -> n b) -> ReaderT r m a -> ReaderT r n b #
Transform the computation inside a ReaderT
.
runReaderT
(mapReaderT
f m) = f .runReaderT
m
:: (r' -> r) | The function to modify the environment. |
-> ReaderT r m a | Computation to run in the modified environment. |
-> ReaderT r' m a |
Execute a computation in a modified environment
(a more general version of local
).
runReaderT
(withReaderT
f m) =runReaderT
m . f
liftCallCC :: CallCC m a b -> CallCC (ReaderT r m) a b #
Lift a callCC
operation to the new monad.
hoist :: (MFunctor t, Monad m) => (forall a. m a -> n a) -> t m b -> t n b #
Lift a monad morphism from m
to n
into a monad morphism from
(t m)
to (t n)
The first argument to hoist
must be a monad morphism, even though the
type system does not enforce this
class Monad m => MonadReader r (m :: Type -> Type) | m -> r where #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r
is a simple reader monad.
See the instance
declaration below.
Retrieves the monad environment.
:: (r -> r) | The function to modify the environment. |
-> m a |
|
-> m a |
Executes a computation in a modified environment.
:: (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
Instances
type ReaderSoup = ReaderSoup_ ARec Source #
The type of ReaderSoup_
your application will eat
type family ContextFromName (l :: Symbol) :: * Source #
Associates the type-level label to the reader context
Instances
type ContextFromName "katip" Source # | |
Defined in Control.Monad.ReaderSoup.Katip | |
type ContextFromName "resource" Source # | |
Defined in Control.Monad.ReaderSoup.Resource |
class SoupContext c t | c -> t where Source #
A class for the contexts that have an associated monad transformer that can be turned into a ReaderT of this context, and the type of monad over which they can run.
toReaderT :: Monad m => t m a -> ReaderT c m a Source #
Turn this monad trans into an actual ReaderT
fromReaderT :: Monad m => ReaderT c m a -> t m a Source #
Reconstruct this monad trans from an actual ReaderT
Instances
SoupContext KatipContextTState KatipContextT Source # | |
Defined in Control.Monad.ReaderSoup.Katip toReaderT :: Monad m => KatipContextT m a -> ReaderT KatipContextTState m a Source # fromReaderT :: Monad m => ReaderT KatipContextTState m a -> KatipContextT m a Source # | |
SoupContext InternalState ResourceT Source # | |
Defined in Control.Monad.ReaderSoup.Resource toReaderT :: Monad m => ResourceT m a -> ReaderT InternalState m a Source # fromReaderT :: Monad m => ReaderT InternalState m a -> ResourceT m a Source # |
type CanBeScoopedIn_ r t ctxs l = (IsInSoup_ r ctxs l, KnownSymbol l, SoupContext (ContextFromName l) t) Source #
type CanBeScoopedIn t ctxs l = CanBeScoopedIn_ ARec t ctxs l Source #
type CanRunSoupContext l t = SoupContext (ContextFromName l) t Source #
askSoup :: IsInSoup_ r ctxs l => Label l -> ReaderSoup_ r ctxs (ContextFromName l) Source #
filtering :: RecSubset ARec ctxs' ctxs (RImage ctxs' ctxs) => ReaderSoup ctxs' a -> ReaderSoup ctxs a Source #
Permits to select only a part of the whole contexts, to locally decide which part of the ReaderSoup will be exposed, and remove ambiguity.
picking :: CanBeScoopedIn_ r t ctxs l => Label l -> t IO a -> ReaderSoup_ r ctxs a Source #
Like dipping
, but instead of Spoon_
runs some preferential Reader-like
monad. That permits to reuse some already existing monad from an existing
library (ResourceT, KatipContextT, etc.) if you cannot just use a MonadReader
instance.
scooping :: CanBeScoopedIn_ r t ctxs l => Label l -> t (ReaderSoup_ r ctxs) a -> ReaderSoup_ r ctxs a Source #
Like picking
, but gives you more context: instead of just running over
IO, it makes the monad run over the whole soup (so instances of MonadXXX
classes defined over the whole soup can still be used).
pouring :: forall l ctxs t a r. CanBeScoopedIn_ r t ctxs l => Label l -> ReaderSoup_ r ctxs a -> t (ReaderSoup_ r ctxs) a Source #
The opposite of scooping
.
Low-level API
data ElField (field :: (Symbol, Type)) where #
A value with a phantom Symbol
label. It is not a
Haskell Functor
, but it is used in many of the same places a
Functor
is used in vinyl.
Instances
type CookedReaderSoup = ReaderSoup_ Rec Source #
A ReaderSoup_
ready to be eaten
cookReaderSoup :: NatToInt (RLength ctxs) => ReaderSoup ctxs a -> CookedReaderSoup ctxs a Source #
Turns a ReaderSoup_
into something than is ready to be eaten
pickTopping :: KnownSymbol l => CookedReaderSoup ((l ::: c) ': ctxs) a -> ReaderT c (CookedReaderSoup ctxs) a Source #
Extracts a ReaderT of the first context so it can be eaten
eatTopping :: KnownSymbol l => CookedReaderSoup ((l ::: c) ': ctxs) a -> c -> CookedReaderSoup ctxs a Source #
Consumes the first context in the record
finishBroth :: CookedReaderSoup '[] a -> IO a Source #
Once all contexts have been eaten, leaves only the base monad
rioToSpoon :: forall l ctxs a r. IsInSoup_ r ctxs l => ReaderT (ContextFromName l) IO a -> Spoon_ r ctxs l a Source #
If you have a code that cannot cope with any MonadReader but explicitly wants a ReaderT
spoonToReaderT :: forall l ctxs a r. (IsInSoup_ r ctxs l, KnownSymbol l) => Spoon_ r ctxs l a -> ReaderT (ContextFromName l) (ReaderSoup_ r ctxs) a Source #
Converting Spoon back to a ReaderT has to happen in the ReaderSoup because we need the global context
dipping :: Label l -> Spoon_ r ctxs l a -> ReaderSoup_ r ctxs a Source #
Brings forth one context of the whole soup, giving a MonadReader instance of just this context. This makes it possible that the same context type occurs several times in the broth, because the Label will disambiguate them.
withSpoon :: forall l ctxs t a r. CanBeScoopedIn_ r t ctxs l => t (ReaderSoup_ r ctxs) a -> Spoon_ r ctxs l a Source #
Converts an action in some ReaderT-like monad to Spoon_
, this
monad being determined by c
. This is for code that cannot cope with any
MonadReader and want some specific monad.