Safe Haskell | None |
---|---|
Language | Haskell2010 |
Defines newtype
s that serve as combinators
to compose deriving via strategies.
Synopsis
- newtype Coerce (to :: *) m (a :: *) = Coerce (m a)
- newtype Rename (oldtag :: k) m (a :: *) = Rename (m a)
- newtype Field (field :: Symbol) (oldtag :: k) m (a :: *) = Field (m a)
- newtype Pos (pos :: Nat) (oldtag :: k) m (a :: *) = Pos (m a)
- newtype Ctor (ctor :: Symbol) (oldtag :: k) m (a :: *) = Ctor (m a)
- newtype Lift m (a :: *) = Lift (m a)
- newtype ((t2 :: (* -> *) -> * -> *) :.: (t1 :: (* -> *) -> * -> *)) (m :: * -> *) (a :: *) = (:.:) (m a)
Documentation
newtype Coerce (to :: *) m (a :: *) Source #
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
instance of
HasReader
"a" Int
to a
MonadReader
(Reader Int)
instance using HasReader
"a" MyIntCoercible Int MyInt
.
Coerce (m a) |
Instances
(Coercible from to, HasSink tag from m) => HasSink (tag :: k) to (Coerce to m) Source # | Convert the state using safe coercion. |
(Coercible from to, HasSource tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasSource (tag :: k) to (Coerce to m) Source # | |
(Coercible from to, HasReader tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasReader (tag :: k) to (Coerce to m) Source # | Convert the environment using safe coercion. |
(Coercible from to, HasState tag from m, forall x y. Coercible x y => Coercible (m x) (m y)) => HasState (tag :: k) to (Coerce to m) Source # | Convert the state using safe coercion. |
Monad m => Monad (Coerce to m) Source # | |
Functor m => Functor (Coerce to m) Source # | |
Applicative m => Applicative (Coerce to m) Source # | |
Defined in Capability.Accessors | |
MonadIO m => MonadIO (Coerce to m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Coerce to m) Source # | |
type PrimState (Coerce to m) Source # | |
Defined in Capability.Accessors |
newtype Rename (oldtag :: k) m (a :: *) Source #
Rename the tag.
Example:
newtype MyReader a = MyReader (Reader Int a) deriving (HasReader "foo" Int) via Rename "bar" (MonadReader (Reader Int))
Converts the
instance of
HasReader
"bar" Int
to a
MonadReader
(Reader Int)
instance by renaming the tag.HasReader
"foo" Int
Note, that MonadReader
itself does not fix a tag,
and Rename
is redundant in this example.
See Pos
below for a common use-case.
Rename (m a) |
Instances
HasSink oldtag s m => HasSink (newtag :: k1) s (Rename oldtag m) Source # | Rename the tag. |
HasSource oldtag r m => HasSource (newtag :: k1) r (Rename oldtag m) Source # | Rename the tag. |
HasReader oldtag r m => HasReader (newtag :: k1) r (Rename oldtag m) Source # | Rename the tag. |
HasState oldtag s m => HasState (newtag :: k1) s (Rename oldtag m) Source # | Rename the tag. |
HasCatch oldtag e m => HasCatch (newtag :: k1) e (Rename oldtag m) Source # | Rename the tag. Apply cautiously. E.g. the following code produces colliding instances,
where exceptions thrown in 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 :: k1) e (Rename oldtag m) Source # | Rename the tag. |
Monad m => Monad (Rename oldtag m) Source # | |
Functor m => Functor (Rename oldtag m) Source # | |
Applicative m => Applicative (Rename oldtag m) Source # | |
Defined in Capability.Accessors pure :: a -> Rename oldtag m a # (<*>) :: Rename oldtag m (a -> b) -> Rename oldtag m a -> Rename oldtag m b # liftA2 :: (a -> b -> c) -> Rename oldtag m a -> Rename oldtag m b -> Rename oldtag m c # (*>) :: Rename oldtag m a -> Rename oldtag m b -> Rename oldtag m b # (<*) :: Rename oldtag m a -> Rename oldtag m b -> Rename oldtag m a # | |
MonadIO m => MonadIO (Rename oldtag m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Rename oldtag m) Source # | |
type PrimState (Rename oldtag m) Source # | |
Defined in Capability.Accessors |
newtype Field (field :: Symbol) (oldtag :: k) m (a :: *) Source #
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
instance of
HasReader
() Foo
to a
MonadReader
(Reader Foo)
instance by focusing on the field HasReader
"foo" Intfoo
in the Foo
record.
See Rename
for a way to change the tag.
Field (m a) |
Instances
(tag ~ field, HasField' field record v, HasState oldtag record m) => HasSink (tag :: Symbol) v (Field field oldtag m) Source # | Zoom in on the record field |
(tag ~ field, HasField' field record v, HasSource oldtag record m) => HasSource (tag :: Symbol) v (Field field oldtag m) Source # | |
(tag ~ field, HasField' field record v, HasReader oldtag record m) => HasReader (tag :: Symbol) v (Field field oldtag m) Source # | Zoom in on the record field |
(tag ~ field, HasField' field record v, HasState oldtag record m) => HasState (tag :: Symbol) v (Field field oldtag m) Source # | Zoom in on the record field |
Monad m => Monad (Field field oldtag m) Source # | |
Functor m => Functor (Field field oldtag m) Source # | |
Applicative m => Applicative (Field field oldtag m) Source # | |
Defined in Capability.Accessors pure :: a -> Field field oldtag m a # (<*>) :: Field field oldtag m (a -> b) -> Field field oldtag m a -> Field field oldtag m b # liftA2 :: (a -> b -> c) -> Field field oldtag m a -> Field field oldtag m b -> Field field oldtag m c # (*>) :: Field field oldtag m a -> Field field oldtag m b -> Field field oldtag m b # (<*) :: Field field oldtag m a -> Field field oldtag m b -> Field field oldtag m a # | |
MonadIO m => MonadIO (Field field oldtag m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Field field oldtag m) Source # | |
type PrimState (Field field oldtag m) Source # | |
Defined in Capability.Accessors |
newtype Pos (pos :: Nat) (oldtag :: k) m (a :: *) Source #
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
instance of
HasReader
() (Int, Bool)
to a
MonadReader
(Reader (Int, Bool))
instance
by focusing on the first element of the tuple.HasReader
1 Int
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))))
Pos (m a) |
Instances
(tag ~ pos, HasPosition' pos struct v, HasState oldtag struct m) => HasSink (tag :: Nat) v (Pos pos oldtag m) Source # | Zoom in on the field at position |
(tag ~ pos, HasPosition' pos struct v, HasSource oldtag struct m) => HasSource (tag :: Nat) v (Pos pos oldtag m) Source # | |
(tag ~ pos, HasPosition' pos struct v, HasReader oldtag struct m) => HasReader (tag :: Nat) v (Pos pos oldtag m) Source # | Zoom in on the field at position |
(tag ~ pos, HasPosition' pos struct v, HasState oldtag struct m) => HasState (tag :: Nat) v (Pos pos oldtag m) Source # | Zoom in on the field at position |
Monad m => Monad (Pos pos oldtag m) Source # | |
Functor m => Functor (Pos pos oldtag m) Source # | |
Applicative m => Applicative (Pos pos oldtag m) Source # | |
Defined in Capability.Accessors pure :: a -> Pos pos oldtag m a # (<*>) :: Pos pos oldtag m (a -> b) -> Pos pos oldtag m a -> Pos pos oldtag m b # liftA2 :: (a -> b -> c) -> Pos pos oldtag m a -> Pos pos oldtag m b -> Pos pos oldtag m c # (*>) :: Pos pos oldtag m a -> Pos pos oldtag m b -> Pos pos oldtag m b # (<*) :: Pos pos oldtag m a -> Pos pos oldtag m b -> Pos pos oldtag m a # | |
MonadIO m => MonadIO (Pos pos oldtag m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Pos pos oldtag m) Source # | |
type PrimState (Pos pos oldtag m) Source # | |
Defined in Capability.Accessors |
newtype Ctor (ctor :: Symbol) (oldtag :: k) m (a :: *) Source #
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
instance of
HasThrow
() "MyError"
to a
MonadError
(ExceptT MyError Identity)
instance by wrapping thrown HasThrow
"ErrB" StringString
s in the ErrB
constructor.
Ctor (m a) |
Instances
(AsConstructor' ctor sum e, HasCatch oldtag sum m) => HasCatch (ctor :: Symbol) e (Ctor ctor oldtag m) Source # | Catch an exception of type |
(AsConstructor' ctor sum e, HasThrow oldtag sum m) => HasThrow (ctor :: Symbol) e (Ctor ctor oldtag m) Source # | Wrap the exception |
Monad m => Monad (Ctor ctor oldtag m) Source # | |
Functor m => Functor (Ctor ctor oldtag m) Source # | |
Applicative m => Applicative (Ctor ctor oldtag m) Source # | |
Defined in Capability.Accessors pure :: a -> Ctor ctor oldtag m a # (<*>) :: Ctor ctor oldtag m (a -> b) -> Ctor ctor oldtag m a -> Ctor ctor oldtag m b # liftA2 :: (a -> b -> c) -> Ctor ctor oldtag m a -> Ctor ctor oldtag m b -> Ctor ctor oldtag m c # (*>) :: Ctor ctor oldtag m a -> Ctor ctor oldtag m b -> Ctor ctor oldtag m b # (<*) :: Ctor ctor oldtag m a -> Ctor ctor oldtag m b -> Ctor ctor oldtag m a # | |
MonadIO m => MonadIO (Ctor ctor oldtag m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Ctor ctor oldtag m) Source # | |
type PrimState (Ctor ctor oldtag m) Source # | |
Defined in Capability.Accessors |
newtype Lift m (a :: *) Source #
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
instance of the underlying
HasState
"foo" Bool
over the
MonadState
(State Bool)StateT Int
monad transformer.
Lift (m a) |
Instances
(HasSink tag a m, MonadTrans t, Monad (t m)) => HasSink (tag :: k) a (Lift (t m)) Source # | Lift one layer in a monad transformer stack. Note, that if the deriving (HasSink tag w) via SinkLog (Lift (SomeTrans (MonadState SomeStateMonad))) over deriving (HasSink tag w) via Lift (SomeTrans (SinkLog (MonadState SomeStateMonad))) |
(HasSource tag r m, MonadTrans t, Monad (t m)) => HasSource (tag :: k) r (Lift (t m)) Source # | |
(HasReader tag r m, MonadTransControl t, Monad (t m)) => HasReader (tag :: k) r (Lift (t m)) Source # | Lift one layer in a monad transformer stack. |
(HasState tag s m, MonadTrans t, Monad (t m)) => HasState (tag :: k) s (Lift (t m)) Source # | Lift one layer in a monad transformer stack. |
(HasCatch tag e m, MonadTransControl t, Monad (t m)) => HasCatch (tag :: k) e (Lift (t m)) Source # | Lift one layer in a monad transformer stack. |
(HasThrow tag e m, MonadTrans t, Monad (t m)) => HasThrow (tag :: k) e (Lift (t m)) Source # | Lift one layer in a monad transformer stack. |
Monad m => Monad (Lift m) Source # | |
Functor m => Functor (Lift m) Source # | |
Applicative m => Applicative (Lift m) Source # | |
MonadIO m => MonadIO (Lift m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad (Lift m) Source # | |
(HasWriter tag w m, MonadTransUnlift t, Monad (t m)) => HasWriter (tag :: Type) w (Lift (t m)) Source # | Lift one layer in a monad transformer stack. Note, that if the deriving (HasWriter tag w) via WriterLog (Lift (SomeTrans (MonadState SomeStateMonad))) over deriving (HasWriter tag w) via Lift (SomeTrans (WriterLog (MonadState SomeStateMonad))) |
type PrimState (Lift m) Source # | |
Defined in Capability.Accessors |
newtype ((t2 :: (* -> *) -> * -> *) :.: (t1 :: (* -> *) -> * -> *)) (m :: * -> *) (a :: *) infixr 9 Source #
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. wrapError
.
(:.:) (m a) infixr 9 |
Instances
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasSink tag a (t2 (t1 m))) => HasSink (tag :: k) a ((t2 :.: t1) m) Source # | Compose two accessors. |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasSource tag r (t2 (t1 m))) => HasSource (tag :: k) r ((t2 :.: t1) m) Source # | |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasReader tag r (t2 (t1 m))) => HasReader (tag :: k) r ((t2 :.: t1) m) Source # | Compose two accessors. |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasState tag s (t2 (t1 m))) => HasState (tag :: k) s ((t2 :.: t1) m) Source # | Compose two accessors. |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasCatch tag e (t2 (t1 m))) => HasCatch (tag :: k) e ((t2 :.: t1) m) Source # | Compose two accessors. |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasThrow tag e (t2 (t1 m))) => HasThrow (tag :: k) e ((t2 :.: t1) m) Source # | Compose two accessors. |
(forall x. Coercible (m x) (t2 (t1 m) x), Monad m, HasWriter tag w (t2 (t1 m))) => HasWriter (tag :: k) w ((t2 :.: t1) m) Source # | Compose two accessors. |
Monad m => Monad ((t2 :.: t1) m) Source # | |
Functor m => Functor ((t2 :.: t1) m) Source # | |
Applicative m => Applicative ((t2 :.: t1) m) Source # | |
Defined in Capability.Accessors pure :: a -> (t2 :.: t1) m a # (<*>) :: (t2 :.: t1) m (a -> b) -> (t2 :.: t1) m a -> (t2 :.: t1) m b # liftA2 :: (a -> b -> c) -> (t2 :.: t1) m a -> (t2 :.: t1) m b -> (t2 :.: t1) m c # (*>) :: (t2 :.: t1) m a -> (t2 :.: t1) m b -> (t2 :.: t1) m b # (<*) :: (t2 :.: t1) m a -> (t2 :.: t1) m b -> (t2 :.: t1) m a # | |
MonadIO m => MonadIO ((t2 :.: t1) m) Source # | |
Defined in Capability.Accessors | |
PrimMonad m => PrimMonad ((t2 :.: t1) m) Source # | |
type PrimState ((t2 :.: t1) m) Source # | |
Defined in Capability.Accessors |