HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecapability-0.5.0.1Haskell2010

Capability.Reader.Internal.Class

  • 1 class
  • 9 values
classclass (Monad m, HasSource tag r m) => HasReader (tag :: k) r (m :: Type -> Type) | tag m -> r where
#

Reader capability

An instance should fulfill the following laws. At this point these laws are not definitive, see https://github.com/haskell/mtl/issues/5.

Property
k <*> ask @t = ask @t <**> k
Property
ask @t *> m = m = m <* ask @t
Property
local @t f (ask @t) = fmap f (ask @t)
Property
local @t f . local @t g = local @t (g . f)
Property
local @t f (pure x) = pure x
Property
local @t f (m >>= \x -> k x) = local @t f m >>= \x -> local @t f (k x)
Property
reader @t f = f <$> ask @t

Methods

  • local_ :: Proxy# tag -> (r -> r) -> m a -> m a

    For technical reasons, this method needs an extra proxy argument. You only need it if you are defining new instances of HasReader. Otherwise, you will want to use local. See local for more documentation.

  • reader_ :: Proxy# tag -> (r -> a) -> m a

    For technical reasons, this method needs an extra proxy argument. You only need it if you are defining new instances of HasReader. Otherwise, you will want to use reader. See reader for more documentation.

Instances12HasSource, HasReader, Reified, …
  • HasState tag r m => HasReader tag r (ReadStatePure m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan
  • MonadReader r m => HasReader tag r (MonadReader m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan
  • (HasReader tag r m, MonadTransControl t, Monad (t m)) => HasReader tag r (Lift (t m))Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Lift one layer in a monad transformer stack.

  • (HasState tag r m, MonadMask m) => HasReader tag r (ReadState m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan
  • (Coercible from to, HasReader tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasReader tag to (Coerce to m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Convert the environment using safe coercion.

  • HasReader oldtag r m => HasReader newtag r (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Rename the tag.

  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasReader tag r (t2 (t1 m))) => HasReader tag r ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Compose two accessors.

  • (Monad m, Reifies s (Reified tag (HasReader tag r) m)) => HasReader tag r (Reflected s (HasReader tag r) m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Class
  • (Monad m, Reifies s (Reified tag (HasReader tag r) m)) => HasSource tag r (Reflected s (HasReader tag r) m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Class
  • (tag ~ field, HasField' field record v, HasReader oldtag record m) => HasReader tag v (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Zoom in on the record field field of type v in the environment record.

  • (tag ~ pos, HasPosition' pos struct v, HasReader oldtag struct m) => HasReader tag v (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Reader.Internal.Strategies · orphan

    Zoom in on the field at position pos of type v in the environment struct.

  • data Reified tag (HasReader tag r)
    • ReifiedReader_readerSource :: Reified tag (HasSource tag r) m_local :: forall a. (r -> r) -> m a -> m a_reader :: forall a. (r -> a) -> m a
    Defined in capability-0.5.0.1 · Capability.Reader.Internal.Class
valueask :: HasReader tag r m => m r
#

ask @tag retrieves the environment of the reader capability tag.

valueasks :: HasReader tag r m => (r -> a) -> m a
#

asks @tag retrieves the image by f of the environment of the reader capability tag.

Property
asks @tag f = f <$> ask @tag
valuelocal :: HasReader tag r m => (r -> r) -> m a -> m a
#

local @tag f m runs the monadic action m in a modified environment e' = f e, where e is the environment of the reader capability tag. Symbolically: return e = ask @tag.

valuereader :: HasReader tag r m => (r -> a) -> m a
#

reader @tag act lifts a purely environment-dependent action act to a monadic action in an arbitrary monad m with capability HasReader.

It happens to coincide with asks: reader = asks.

valuemagnify
  1. :: (forall x. Coercible (t m x) (m x), HasReader innertag inner (t m), All cs m)
  2. => forall (m' :: Type -> Type). All (HasReader innertag inner ': cs) m' => m' a
  3. -> m a
#

Execute the given reader action on a sub-component of the current context as defined by the given transformer t, retaining arbitrary capabilities listed in cs.

See the similar Capability.State.zoom function for more details and examples.

This function is experimental and subject to change. See https://github.com/tweag/capability/issues/46.

data familydata family Reified (tag :: k) (c :: Capability) (m :: Type -> Type)
#
Reified tag capability m

Defines the dictionary type for the methods of capability under tag in the monad m. Refer to interpret_ for an example use-case.

For example, the Capability.Sink.HasSink capability has the method Capability.Sink.yield :: a -> m (). The corresponding dictionary type is defined as follows.

Example1 expression
:{  data instance Reified tag (HasSink tag a) m =    ReifiedSink { _yield :: forall a. a -> m () }  :}

Superclass dictionaries are represented as nested records. For example, the Capability.State.HasState capability has the superclasses Capability.Source.HasSource and Capability.Sink.HasSink and the method Capability.State.state :: (s -> (a, s)) -> m a. The corresponding dictionary type is defined as follows.

Example1 expression
:{  data instance Reified tag (HasState tag s) m =    ReifiedState      { _stateSource :: Reified tag (HasSource tag s) m,        _stateSink :: Reified tag (HasSink tag s) m,        _state :: forall a. (s -> (a, s)) -> m a      }  :}
Instances7Reified, …
constructorReifiedReader
#

Fields

  • _readerSource :: Reified tag (HasSource tag r) m
  • _local :: forall a. (r -> r) -> m a -> m a
  • _reader :: forall a. (r -> a) -> m a
value_local
  1. :: Reified tag (HasReader tag r) m
  2. -> forall a. (r -> r) -> m a -> m a
#
value_reader :: Reified tag (HasReader tag r) m -> forall a. (r -> a) -> m a
#
value_readerSource
  1. :: Reified tag (HasReader tag r) m
  2. -> Reified tag (HasSource tag r) m
#