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.Accessors

Defines newtypes that serve as combinators to compose deriving via strategies.

  • 7 types
newtypenewtype Coerce to (m :: Type -> Type) a
#

Coerce the type in the context m to to.

Example:

newtype MyInt = MyInt Int
newtype MyReader a = MyReader (Reader Int a)
  deriving (HasReader "a" MyInt) via
    Coerce MyInt (MonadReader (Reader Int))

Converts the Capability.Reader.HasReader "a" Int instance of Capability.Reader.MonadReader (Reader Int) to a Capability.Reader.HasReader "a" MyInt instance using Coercible Int MyInt.

Constructors

Instances10HasReader, HasSource, HasState, HasSink, Monad, Functor, …
  • (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.

  • (Coercible from to, HasSource tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasSource tag to (Coerce to m)Defined in capability-0.5.0.1 · Capability.Source.Internal.Strategies · orphan
  • (Coercible from to, HasState tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasState tag to (Coerce to m)Defined in capability-0.5.0.1 · Capability.State.Internal.Strategies · orphan

    Convert the state using safe coercion.

  • (Coercible from to, HasSink tag from m) => HasSink tag to (Coerce to m)Defined in capability-0.5.0.1 · Capability.Sink.Internal.Strategies · orphan

    Convert the state using safe coercion.

  • Monad m => Monad (Coerce to m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Coerce to m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Coerce to m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Coerce to m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Coerce to m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Coerce to m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype Rename (oldtag :: k) (m :: Type -> Type) a
#

Rename the tag.

Example:

newtype MyReader a = MyReader (Reader Int a)
  deriving (HasReader "foo" Int) via
    Rename "bar" (MonadReader (Reader Int))

Converts the Capability.Reader.HasReader "bar" Int instance of Capability.Reader.MonadReader (Reader Int) to a Capability.Reader.HasReader "foo" Int instance by renaming the tag.

Note, that Capability.Reader.MonadReader itself does not fix a tag, and Rename is redundant in this example.

See Pos below for a common use-case.

Constructors

Instances12HasCatch, HasThrow, HasReader, HasSource, HasState, HasSink, …
  • HasCatch oldtag e m => HasCatch newtag e (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Error

    Rename the tag.

    Apply cautiously. E.g. the following code produces colliding instances, where exceptions thrown in "Foo" cannot be distinguished from exceptions thrown in "Bar" and vice-versa.

    newtype Bad a = Bad (IO a)
      deriving (Functor, Applicative, Monad)
      deriving
        ( HasThrow "Foo" m
        , HasCatch "Foo" m
        ) via Rename () (MonadUnliftIO SomeError IO)
      deriving
        ( HasThrow "Bar" m
        , HasCatch "Bar" m
        ) via Rename () (MonadUnliftIO SomeError IO)
  • HasThrow oldtag e m => HasThrow newtag e (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Error

    Rename the tag.

    Apply cautiously. See HasCatch newtag e (Rename oldtag m).

  • 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.

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

    Rename the tag.

  • HasState oldtag s m => HasState newtag s (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.State.Internal.Strategies · orphan

    Rename the tag.

  • HasSink oldtag s m => HasSink newtag s (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Sink.Internal.Strategies · orphan

    Rename the tag.

  • Monad m => Monad (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Rename oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Rename oldtag m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype Field (field :: Symbol) (oldtag :: k) (m :: Type -> Type) a
#

Access the record field field in the context m.

Example:

data Foo = Foo { foo :: Int }
newtype MyReader a = MyReader (Reader Foo a)
  deriving (HasReader "foo" Int) via
    Field "foo" () (MonadReader (Reader Foo))

Converts the Capability.Reader.HasReader () Foo instance of Capability.Reader.MonadReader (Reader Foo) to a Capability.Reader.HasReader "foo" Int instance by focusing on the field foo in the Foo record.

See Rename for a way to change the tag.

Constructors

Instances10HasReader, HasSource, HasState, HasSink, Monad, Functor, …
  • (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 ~ field, HasField' field record v, HasSource oldtag record m) => HasSource tag v (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Source.Internal.Strategies · orphan
  • (tag ~ field, HasField' field record v, HasState oldtag record m) => HasState tag v (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.State.Internal.Strategies · orphan

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

  • (tag ~ field, HasField' field record v, HasState oldtag record m) => HasSink tag v (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Sink.Internal.Strategies · orphan

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

  • Monad m => Monad (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Field field oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Field field oldtag m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype Pos (pos :: Nat) (oldtag :: k) (m :: Type -> Type) a
#

Access the value at position pos in the context m.

Example:

newtype MyReader a = MyReader (Reader (Int, Bool) a)
  deriving (HasReader 1 Int) via
    Pos 1 () (MonadReader (Reader (Int, Bool)))

Converts the Capability.Reader.HasReader () (Int, Bool) instance of Capability.Reader.MonadReader (Reader (Int, Bool)) to a Capability.Reader.HasReader 1 Int instance by focusing on the first element of the tuple.

The implied number tag can be renamed to a more descriptive name using the Rename combinator:

newtype MyReader a = MyReader (Reader (Int, Bool) a)
  deriving (HasReader "foo" Int) via
    Rename 1 (Pos 1 () (MonadReader (Reader (Int, Bool))))

Constructors

Instances10HasReader, HasSource, HasState, HasSink, Monad, Functor, …
  • (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.

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

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

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

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

  • Monad m => Monad (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Pos pos oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Pos pos oldtag m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype Ctor (ctor :: Symbol) (oldtag :: k) (m :: Type -> Type) a
#

Choose the given constructor in the sum-type in context m.

Example:

data MyError = ErrA String | ErrB String
newtype MyExcept a = MyExcept (ExceptT MyError Identity a)
  deriving (HasThrow "ErrB" String) via
    Ctor "ErrB" () (MonadError (ExceptT MyError Identity))

Converts the HasThrow () "MyError" instance of MonadError (ExceptT MyError Identity) to a HasThrow "ErrB" String instance by wrapping thrown Strings in the ErrB constructor.

Constructors

Instances8HasCatch, HasThrow, Monad, Functor, Applicative, MonadIO, …
  • (AsConstructor' ctor sum e, HasCatch oldtag sum m) => HasCatch ctor e (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Error

    Catch an exception of type sum if its constructor matches ctor.

  • (AsConstructor' ctor sum e, HasThrow oldtag sum m) => HasThrow ctor e (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Error

    Wrap the exception e with the constructor ctor to throw an exception of type sum.

  • Monad m => Monad (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Ctor ctor oldtag m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Ctor ctor oldtag m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype Lift (m :: Type -> Type) a
#

Skip one level in a monad transformer stack.

Note, that instances generated with this strategy can incur a performance penalty.

Example:

newtype MyStates a = MyStates (StateT Int (State Bool) a)
  deriving (HasState "foo" Bool) via
    Lift (StateT Int (MonadState (State Bool)))

Uses the MonadTrans instance of StateT Int to lift the Capability.State.HasState "foo" Bool instance of the underlying Capability.State.MonadState (State Bool) over the StateT Int monad transformer.

Constructors

Instances12HasCatch, HasThrow, HasReader, HasSource, HasState, HasSink, …
  • (HasCatch tag e m, MonadTransControl t, Monad (t m)) => HasCatch tag e (Lift (t m))Defined in capability-0.5.0.1 · Capability.Error

    Lift one layer in a monad transformer stack.

  • (HasThrow tag e m, MonadTrans t, Monad (t m)) => HasThrow tag e (Lift (t m))Defined in capability-0.5.0.1 · Capability.Error

    Lift one layer in a monad transformer stack.

  • (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.

  • (HasSource tag r m, MonadTrans t, Monad (t m)) => HasSource tag r (Lift (t m))Defined in capability-0.5.0.1 · Capability.Source.Internal.Strategies · orphan
  • (HasState tag s m, MonadTrans t, Monad (t m)) => HasState tag s (Lift (t m))Defined in capability-0.5.0.1 · Capability.State.Internal.Strategies · orphan

    Lift one layer in a monad transformer stack.

  • (HasSink tag a m, MonadTrans t, Monad (t m)) => HasSink tag a (Lift (t m))Defined in capability-0.5.0.1 · Capability.Sink.Internal.Strategies · orphan

    Lift one layer in a monad transformer stack.

    Note, that if the HasSink instance is based on HasState, then it is more efficient to apply Lift to the underlying state capability. E.g. you should favour

    deriving (HasSink tag w) via
      SinkLog (Lift (SomeTrans (MonadState SomeStateMonad)))

    over

    deriving (HasSink tag w) via
      Lift (SomeTrans (SinkLog (MonadState SomeStateMonad)))
  • Monad m => Monad (Lift m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor (Lift m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative (Lift m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO (Lift m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad (Lift m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState (Lift m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors
newtypenewtype (:.:) (t2 :: (Type -> Type) -> Type -> Type) (t1 :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a
#

Compose two accessors.

This is not necessary in deriving via clauses, but in places where a transformer is expected as a type argument. E.g. HasError.wrapError.

Constructors

  • (:.:) (m a)infixr 9
Instances13HasCatch, HasThrow, HasReader, HasSource, HasState, HasSink, …
  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasCatch tag e (t2 (t1 m))) => HasCatch tag e ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Error

    Compose two accessors.

  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasThrow tag e (t2 (t1 m))) => HasThrow tag e ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Error

    Compose two accessors.

  • (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.

  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasSource tag r (t2 (t1 m))) => HasSource tag r ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Source.Internal.Strategies · orphan
  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasState tag s (t2 (t1 m))) => HasState tag s ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.State.Internal.Strategies · orphan

    Compose two accessors.

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

    Compose two accessors.

  • (forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasWriter tag w (t2 (t1 m))) => HasWriter tag w ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Writer

    Compose two accessors.

  • Monad m => Monad ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Functor m => Functor ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Accessors
  • Applicative m => Applicative ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Accessors
  • MonadIO m => MonadIO ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Accessors
  • PrimMonad m => PrimMonad ((:.:) t2 t1 m)Defined in capability-0.5.0.1 · Capability.Accessors
  • type PrimState ((:.:) t2 t1 m) = PrimState mDefined in capability-0.5.0.1 · Capability.Accessors