Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class Phased (env_ :: (Type -> Type) -> (Type -> Type) -> Type) where
- traverseH :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type). (Applicative f, Typeable f, Typeable g, Typeable h, Typeable m) => (forall x. Typeable x => h x -> f (g x)) -> env_ h m -> f (env_ g m)
- liftA2H :: forall (a :: Type -> Type) (f :: Type -> Type) (f' :: Type -> Type) (m :: Type -> Type). (Typeable a, Typeable f, Typeable f', Typeable m) => (forall x. Typeable x => a x -> f x -> f' x) -> env_ a m -> env_ f m -> env_ f' m
- liftAH :: forall deps_ phases phases' m. (Phased deps_, Typeable phases, Typeable phases', Typeable m) => (forall x. Typeable x => phases x -> phases' x) -> deps_ phases m -> deps_ phases' m
- pullPhase :: forall (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Applicative f, Typeable f, Typeable g, Typeable m) => env_ (Compose f g) m -> f (env_ g m)
- mapPhase :: forall (f :: Type -> Type) (f' :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Typeable f, Typeable f', Typeable g, Typeable m) => (forall x. Typeable x => f x -> f' x) -> env_ (Compose f g) m -> env_ (Compose f' g) m
- liftA2Phase :: forall (a :: Type -> Type) (f' :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Typeable a, Typeable f, Typeable f', Typeable g, Typeable m) => (forall x. Typeable x => a x -> f x -> f' x) -> env_ (Compose a g) m -> env_ (Compose f g) m -> env_ (Compose f' g) m
- (>>=) :: Functor f => f x -> (x -> g y) -> Compose f g y
- (>>) :: Functor f => f x -> g y -> Compose f g y
- newtype Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1) = Compose {
- getCompose :: f (g a)
Managing phases
class Phased (env_ :: (Type -> Type) -> (Type -> Type) -> Type) where Source #
Class of 2-parameter environments for which the first parameter h
wraps
each field and corresponds to phases in the construction of the environment,
and the second parameter m
is the effect monad used by each component.
h
will typically be a composition of applicative functors, each one
representing a phase. We advance through the phases by "pulling out" the
outermost phase and running it in some way, until we are are left with a
Constructor
phase, which we can remove using fixEnv
.
Phased
resembles FunctorT, TraversableT and
ApplicativeT
from the barbies library,
although Phased
instances can't be written in terms of them because of the extra Typeable
constraints.
Nothing
:: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type). (Applicative f, Typeable f, Typeable g, Typeable h, Typeable m) | |
=> (forall x. Typeable x => h x -> f (g x)) | Transform to be applied to each field. |
-> env_ h m | |
-> f (env_ g m) |
default traverseH :: forall (h :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type). (Applicative f, Typeable f, Typeable g, Typeable h, Typeable m, Generic (env_ h m), Generic (env_ g m), GTraverseH h g (Rep (env_ h m)) (Rep (env_ g m))) => (forall x. Typeable x => h x -> f (g x)) -> env_ h m -> f (env_ g m) Source #
:: forall (a :: Type -> Type) (f :: Type -> Type) (f' :: Type -> Type) (m :: Type -> Type). (Typeable a, Typeable f, Typeable f', Typeable m) | |
=> (forall x. Typeable x => a x -> f x -> f' x) | Transform to be applied to each field. |
-> env_ a m | |
-> env_ f m | |
-> env_ f' m |
Used to implement liftA2Phase
, typically you should use that function instead.
default liftA2H :: forall (a :: Type -> Type) (f :: Type -> Type) (f' :: Type -> Type) m. (Typeable a, Typeable f, Typeable f', Typeable m, Generic (env_ a m), Generic (env_ f m), Generic (env_ f' m), GLiftA2Phase a f f' (Rep (env_ a m)) (Rep (env_ f m)) (Rep (env_ f' m))) => (forall x. Typeable x => a x -> f x -> f' x) -> env_ a m -> env_ f m -> env_ f' m Source #
Instances
Phased (InductiveEnv rs) Source # | |
Defined in Dep.Env traverseH :: forall h f g (m :: Type -> Type). (Applicative f, Typeable f, Typeable g, Typeable h, Typeable m) => (forall x. Typeable x => h x -> f (g x)) -> InductiveEnv rs h m -> f (InductiveEnv rs g m) Source # liftA2H :: forall a f f' (m :: Type -> Type). (Typeable a, Typeable f, Typeable f', Typeable m) => (forall x. Typeable x => a x -> f x -> f' x) -> InductiveEnv rs a m -> InductiveEnv rs f m -> InductiveEnv rs f' m Source # |
:: forall deps_ phases phases' m. (Phased deps_, Typeable phases, Typeable phases', Typeable m) | |
=> (forall x. Typeable x => phases x -> phases' x) | Transform to be applied to each field. |
-> deps_ phases m | |
-> deps_ phases' m |
Slightly less powerful version of traverseH
.
:: forall (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Applicative f, Typeable f, Typeable g, Typeable m) | |
=> env_ (Compose f g) m | |
-> f (env_ g m) | Environment with the outer |
Take the outermost phase wrapping each component and "pull it outwards", aggregating the phase's applicative effects.
>>>
:{
newtype Foo d = Foo {foo :: String -> d ()} deriving Generic makeIOFoo :: MonadIO m => Foo m makeIOFoo = Foo (liftIO . putStrLn) env :: InductiveEnv '[Foo] (IO `Compose` Constructor (InductiveEnv '[Foo] Identity IO)) IO env = EmptyEnv & AddDep @Foo (putStrLn "io phase" `bindPhase` \() -> constructor (\_ -> makeIOFoo)) ioOutside :: IO (InductiveEnv '[Foo] (Constructor (InductiveEnv '[Foo] Identity IO)) IO) ioOutside = pullPhase env :}
:: forall (f :: Type -> Type) (f' :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Typeable f, Typeable f', Typeable g, Typeable m) | |
=> (forall x. Typeable x => f x -> f' x) | Transform to be applied to each field. |
-> env_ (Compose f g) m | |
-> env_ (Compose f' g) m |
Modify the outermost phase wrapping each component.
>>>
:{
newtype Foo d = Foo {foo :: String -> d ()} deriving Generic makeIOFoo :: MonadIO m => Foo m makeIOFoo = Foo (liftIO . putStrLn) env :: InductiveEnv '[Foo] ((,) Int `Compose` Constructor String) IO env = EmptyEnv & AddDep @Foo ((2,()) `bindPhase` \() -> constructor (\_ -> makeIOFoo)) env' :: InductiveEnv '[Foo] ((,) String `Compose` Constructor String) IO env' = mapPhase (\(n,x) -> (show n,x)) env :}
:: forall (a :: Type -> Type) (f' :: Type -> Type) (f :: Type -> Type) (g :: Type -> Type) (m :: Type -> Type) env_. (Phased env_, Typeable a, Typeable f, Typeable f', Typeable g, Typeable m) | |
=> (forall x. Typeable x => a x -> f x -> f' x) | Binary operation to combine corresponding fields. |
-> env_ (Compose a g) m | |
-> env_ (Compose f g) m | |
-> env_ (Compose f' g) m |
Combine two environments with a function that works on their outermost phases.
Qualified do-notation for building phases
Convenient qualified
do-notation
for defining nested applicative phases wrapped in Compose
s.
BEWARE! Despite its convenience, this do-notation lacks many of the properties we tend to assume when working with do-notation. In particular, it's NOT associative! This means that if we have
Dep.Phases.do somePhase someOtherPhase finalPhase
we CAN'T refactor to
Dep.Phases.do Dep.Phases.do somePhase someOtherPhase finalPhase
It would indeed be useful (it would allow pre-packaging and sharing initial phases as do-blocks) but it isn't supported.
BEWARE#2! Do not use return
in this do-notation.
Some valid examples:
>>>
:{
type Phases = (IO `Compose` IO `Compose` IO) Int phases :: Phases phases = Dep.Phases.do r1 <- pure 1 r2 <- pure 2 pure $ r1 + r2 :}
>>>
:{
type Phases = (IO `Compose` Maybe `Compose` Either Char) Int phases :: Phases phases = Dep.Phases.do pure () Just 5 Left 'e' :}
(>>=) :: Functor f => f x -> (x -> g y) -> Compose f g y Source #
Examples without -XQualifiedDo
:
>>>
:{
type Phases = IO `Compose` IO `Compose` Identity phased :: Phases Int phased = pure 1 Dep.Phases.>>= \i1 -> pure 2 Dep.Phases.>>= \i2 -> pure $ i1 + i2 :}
>>>
:{
type Phases = (IO `Compose` Maybe `Compose` Either Char) Int phases :: Phases phases = pure () Dep.Phases.>>= \_ -> Just 5 Dep.Phases.>>= \_ -> Left 'e' :}
(>>) :: Functor f => f x -> g y -> Compose f g y Source #
Better not use this one without -XQualifiedDo
Re-exports
newtype Compose (f :: k -> Type) (g :: k1 -> k) (a :: k1) infixr 9 #
Right-to-left composition of functors. The composition of applicative functors is always applicative, but the composition of monads is not always a monad.
Compose infixr 9 | |
|
Instances
TestEquality f => TestEquality (Compose f g :: k2 -> Type) | The deduction (via generativity) that if Since: base-4.14.0.0 |
Defined in Data.Functor.Compose | |
Functor f => Generic1 (Compose f g :: k -> Type) | |
(Foldable f, Foldable g) => Foldable (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose fold :: Monoid m => Compose f g m -> m # foldMap :: Monoid m => (a -> m) -> Compose f g a -> m # foldMap' :: Monoid m => (a -> m) -> Compose f g a -> m # foldr :: (a -> b -> b) -> b -> Compose f g a -> b # foldr' :: (a -> b -> b) -> b -> Compose f g a -> b # foldl :: (b -> a -> b) -> b -> Compose f g a -> b # foldl' :: (b -> a -> b) -> b -> Compose f g a -> b # foldr1 :: (a -> a -> a) -> Compose f g a -> a # foldl1 :: (a -> a -> a) -> Compose f g a -> a # toList :: Compose f g a -> [a] # null :: Compose f g a -> Bool # length :: Compose f g a -> Int # elem :: Eq a => a -> Compose f g a -> Bool # maximum :: Ord a => Compose f g a -> a # minimum :: Ord a => Compose f g a -> a # | |
(Eq1 f, Eq1 g) => Eq1 (Compose f g) | Since: base-4.9.0.0 |
(Ord1 f, Ord1 g) => Ord1 (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Read1 f, Read1 g) => Read1 (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Compose f g a) # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Compose f g a] # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Compose f g a) # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Compose f g a] # | |
(Show1 f, Show1 g) => Show1 (Compose f g) | Since: base-4.9.0.0 |
(Traversable f, Traversable g) => Traversable (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Alternative f, Applicative g) => Alternative (Compose f g) | Since: base-4.9.0.0 |
(Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Functor f, Functor g) => Functor (Compose f g) | Since: base-4.9.0.0 |
(Typeable a, Typeable f, Typeable g, Typeable k1, Typeable k2, Data (f (g a))) => Data (Compose f g a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g0. g0 -> c g0) -> Compose f g a -> c (Compose f g a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Compose f g a) # toConstr :: Compose f g a -> Constr # dataTypeOf :: Compose f g a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Compose f g a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Compose f g a)) # gmapT :: (forall b. Data b => b -> b) -> Compose f g a -> Compose f g a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Compose f g a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Compose f g a -> r # gmapQ :: (forall d. Data d => d -> u) -> Compose f g a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Compose f g a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Compose f g a -> m (Compose f g a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Compose f g a -> m (Compose f g a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Compose f g a -> m (Compose f g a) # | |
Monoid (f (g a)) => Monoid (Compose f g a) | Since: base-4.16.0.0 |
Semigroup (f (g a)) => Semigroup (Compose f g a) | Since: base-4.16.0.0 |
Generic (Compose f g a) | |
(Read1 f, Read1 g, Read a) => Read (Compose f g a) | Since: base-4.9.0.0 |
(Show1 f, Show1 g, Show a) => Show (Compose f g a) | Since: base-4.9.0.0 |
(Eq1 f, Eq1 g, Eq a) => Eq (Compose f g a) | Since: base-4.9.0.0 |
(Ord1 f, Ord1 g, Ord a) => Ord (Compose f g a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose compare :: Compose f g a -> Compose f g a -> Ordering # (<) :: Compose f g a -> Compose f g a -> Bool # (<=) :: Compose f g a -> Compose f g a -> Bool # (>) :: Compose f g a -> Compose f g a -> Bool # (>=) :: Compose f g a -> Compose f g a -> Bool # | |
type Rep1 (Compose f g :: k -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
type Rep (Compose f g a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose |