| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Kernmantle.Rope
Description
A Rope connects together various effect Strands that get interlaced
together.
A Strand is an effet with a parameter and an output. No constraint is
placed on the Strand, but once combined in a Rope, that Rope will be
an Arrow and a Profunctor. Strands in a Rope are named via labels to
limit ambiguity.
An action that targets some Strand can be lifted to a Rope that contains
that Strand with the strand function.
Synopsis
- module Data.Profunctor.Trans
- newtype Cayley (f :: k -> Type) (p :: k1 -> k2 -> k) (a :: k1) (b :: k2) = Cayley {
- runCayley :: f (p a b)
- data Rope (record :: RopeRec) (mantle :: [Strand]) (core :: BinEff) a b
- type TightRope = Rope ARec
- type LooseRope = Rope Rec
- tighten :: (RecApplicative m, RPureConstrained (IndexableField m) m) => LooseRope m core :-> TightRope m core
- loosen :: NatToInt (RLength m) => TightRope m core :-> LooseRope m core
- mapRopeCore :: (core a b -> core a' b') -> Rope r m core a b -> Rope r m core a' b'
- mergeStrands :: Label n1 -> Label n2 -> LooseRope ('(n1, binEff) ': ('(n2, binEff) ': mantle)) core :-> LooseRope ('(n1, binEff) ': mantle) core
- type BinEff = * -> * -> *
- type Strand = (Symbol, BinEff)
- type (:::) (a :: k) (b :: k1) = '(a, b)
- type family StrandName t where ...
- type family StrandEff t where ...
- type family InRope l eff rope where ...
- type AllInMantle strands mantle core = (NatToInt (RLength mantle), RecApplicative mantle, RPureConstrained (IndexableField mantle) mantle, LooseRope mantle core `Entwines` strands, TightRope mantle core `Entwines` strands)
- strand :: InRope l eff (Rope r m c) => Label l -> eff :-> Rope r m c
- mapStrand :: InRope l eff (Rope r m c) => Label l -> (eff :-> eff) -> Rope r m c :-> Rope r m c
- weave :: forall name binEff mantle core. Label name -> ((LooseRope ('(name, binEff) ': mantle) core :-> core) -> binEff :-> core) -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core
- weave' :: forall name binEff mantle core. Label name -> (binEff :-> core) -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core
- weaveK :: HasKleisli m core => Label name -> (forall a b. binEff a b -> a -> m b) -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core
- class WeaveAll mantle core where
- retwine :: RetwinableAs r strands core strands' => Rope r strands core :-> Rope r strands' core
- untwine :: LooseRope '[] core :-> core
- type AnyRopeWith strands coreConstraints a b = forall mantle r core. (Rope r mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => Rope r mantle core a b
- type TightRopeWith strands coreConstraints a b = forall mantle core. (TightRope mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => TightRope mantle core a b
- type LooseRopeWith strands coreConstraints a b = forall mantle core. (LooseRope mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => LooseRope mantle core a b
- type family Entwines rope (strands :: [Strand]) :: Constraint where ...
- type family SatisfiesAll (x :: k) (csts :: [k -> Constraint]) :: Constraint where ...
- type (:->) (p :: k -> k1 -> Type) (q :: k -> k1 -> Type) = forall (a :: k) (b :: k1). p a b -> q a b
- data Label (a :: Symbol)
- fromLabel :: IsLabel x a => a
- (&) :: a -> (a -> b) -> b
- mkRope :: (record (Weaver core) mantle -> core a b) -> Rope record mantle core a b
- runRope :: Rope record mantle core a b -> record (Weaver core) mantle -> core a b
Re-exports
module Data.Profunctor.Trans
newtype Cayley (f :: k -> Type) (p :: k1 -> k2 -> k) (a :: k1) (b :: k2) #
Static arrows. Lifted by Applicative.
Cayley has a polymorphic kind since 5.6.
Instances
Rope
data Rope (record :: RopeRec) (mantle :: [Strand]) (core :: BinEff) a b Source #
Rope is a free arrow built out of _several_ binary effects (ie. effects
with kind * -> * -> *). These effects are called Strands, they compose the
mantle, can be interpreted in an interp effect and can be interlaced "on
top" of an existing core effect.
Instances
| TryEffect ex core => TryEffect ex (Rope record mantle core) Source # | |
| ThrowEffect ex core => ThrowEffect ex (Rope record mantle core) Source # | |
| SieveTrans f core => SieveTrans f (Rope record mantle core) Source # | |
| HasAutoIdent eff core => HasAutoIdent eff (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope Methods liftAutoIdent :: (ArrowIdent -> eff a b) -> Rope record mantle core a b Source # | |
| Category core => Category (Rope record mantle core :: Type -> Type -> Type) Source # | |
| Bifunctor core => Bifunctor (Rope record mantle core) Source # | |
| Arrow core => Arrow (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope Methods arr :: (b -> c) -> Rope record mantle core b c # first :: Rope record mantle core b c -> Rope record mantle core (b, d) (c, d) # second :: Rope record mantle core b c -> Rope record mantle core (d, b) (d, c) # (***) :: Rope record mantle core b c -> Rope record mantle core b' c' -> Rope record mantle core (b, b') (c, c') # (&&&) :: Rope record mantle core b c -> Rope record mantle core b c' -> Rope record mantle core b (c, c') # | |
| ArrowZero core => ArrowZero (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope | |
| ArrowPlus core => ArrowPlus (Rope record mantle core) Source # | |
| ArrowChoice core => ArrowChoice (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope Methods left :: Rope record mantle core b c -> Rope record mantle core (Either b d) (Either c d) # right :: Rope record mantle core b c -> Rope record mantle core (Either d b) (Either d c) # (+++) :: Rope record mantle core b c -> Rope record mantle core b' c' -> Rope record mantle core (Either b b') (Either c c') # (|||) :: Rope record mantle core b d -> Rope record mantle core c d -> Rope record mantle core (Either b c) d # | |
| ArrowLoop core => ArrowLoop (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope | |
| Biapplicative core => Biapplicative (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope Methods bipure :: a -> b -> Rope record mantle core a b # (<<*>>) :: Rope record mantle core (a -> b) (c -> d) -> Rope record mantle core a c -> Rope record mantle core b d # biliftA2 :: (a -> b -> c) -> (d -> e -> f) -> Rope record mantle core a d -> Rope record mantle core b e -> Rope record mantle core c f # (*>>) :: Rope record mantle core a b -> Rope record mantle core c d -> Rope record mantle core c d # (<<*) :: Rope record mantle core a b -> Rope record mantle core c d -> Rope record mantle core a b # | |
| Mapping core => Mapping (Rope record mantle core) Source # | |
| Traversing core => Traversing (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope | |
| Choice core => Choice (Rope record mantle core) Source # | |
| Cochoice core => Cochoice (Rope record mantle core) Source # | |
| Closed core => Closed (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope | |
| Strong core => Strong (Rope record mantle core) Source # | |
| Costrong core => Costrong (Rope record mantle core) Source # | |
| Profunctor core => Profunctor (Rope record mantle core) Source # | |
Defined in Control.Kernmantle.Rope Methods dimap :: (a -> b) -> (c -> d) -> Rope record mantle core b c -> Rope record mantle core a d # lmap :: (a -> b) -> Rope record mantle core b c -> Rope record mantle core a c # rmap :: (b -> c) -> Rope record mantle core a b -> Rope record mantle core a c # (#.) :: forall a b c q. Coercible c b => q b c -> Rope record mantle core a b -> Rope record mantle core a c # (.#) :: forall a b c q. Coercible b a => Rope record mantle core b c -> q a b -> Rope record mantle core a c # | |
tighten :: (RecApplicative m, RPureConstrained (IndexableField m) m) => LooseRope m core :-> TightRope m core Source #
mapRopeCore :: (core a b -> core a' b') -> Rope r m core a b -> Rope r m core a' b' Source #
Applies a function on the core action of the Rope
mergeStrands :: Label n1 -> Label n2 -> LooseRope ('(n1, binEff) ': ('(n2, binEff) ': mantle)) core :-> LooseRope ('(n1, binEff) ': mantle) core Source #
Merge two strands that have the same effect type. Keeps the first name.
Binary Effects and Strands
type BinEff = * -> * -> * Source #
The kind for all binary effects. First param is usually an input (contravariant) of the effect and second one an output (covariant).
type Strand = (Symbol, BinEff) Source #
The kind for a named binary effect. Must remain a tuple because that's what vinyl expects.
type family StrandName t where ... Source #
Equations
| StrandName '(name, eff) = name |
type family InRope l eff rope where ... Source #
Tells that a strand of effects '(l,eff) is present in the rope
Equations
| InRope l eff (Rope record mantle core) = (HasField record l mantle mantle eff eff, RecElemFCtx record (Weaver core)) |
type AllInMantle strands mantle core = (NatToInt (RLength mantle), RecApplicative mantle, RPureConstrained (IndexableField mantle) mantle, LooseRope mantle core `Entwines` strands, TightRope mantle core `Entwines` strands) Source #
Useful for functions that want to use tighten/loosen
mapStrand :: InRope l eff (Rope r m c) => Label l -> (eff :-> eff) -> Rope r m c :-> Rope r m c Source #
Rope Interpretation
Arguments
| :: forall name binEff mantle core. Label name | The name of the strand to be woven. |
| -> ((LooseRope ('(name, binEff) ': mantle) core :-> core) -> binEff :-> core) | The interpretation function for the effect, which can depend on the global interpretation function for the rope. |
| -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core | An interpretation function for a |
Adds a new effect strand in the Rope by decribing how to interpret that
in the core. The interpretation function is fed the fixpoint of all
interpretation functions, meaning the interpretation function can itself use
effects in the Rope. For example, given an effect Eff, whose label is
"effect" being interpreted in a core effect CoreEff, one first defines an
interpretation function:
interpret ::
(LooseRope '("effect",Eff) ': mantle) core :-> CoreEff) ->
Eff a b -> CoreEff a b
interpret ::
(LooseRope '("effect",Eff) ': mantle) core :-> CoreEff) ->
(Eff :-> CoreEff)
where p :-> q corresponds to forall a b. p a b -> q a b, and obtain an
interpreter for the strand:
strandInterpreter ::
LooseRope ('("effect",Eff) ': mantle) CoreEff :->
LooseRope mantle CoreEff
strandInterpreter = weave #effect interpret
Arguments
| :: forall name binEff mantle core. Label name | The name of the strand to be woven. |
| -> (binEff :-> core) | The interpretation function for the effect. |
| -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core | An interpretation function for a |
A version of weave where the strand can be directly interpreted in the
core with no need to trigger other effects. For example, given an effect
Eff, whose label is "effect" being interpreted in a core effect CoreEff,
one first defines an interpretation function:
interpret :: Eff a b -> CoreEff a b interpret :: Eff :-> CoreEff
and obtain an interpreter for the strand:
strandInterpreter ::
LooseRope ('("effect",Eff) ': mantle) CoreEff :->
LooseRope mantle CoreEff
strandInterpreter = weave' #effect interpret
weaveK :: HasKleisli m core => Label name -> (forall a b. binEff a b -> a -> m b) -> LooseRope ('(name, binEff) ': mantle) core :-> LooseRope mantle core Source #
A shortcut for weave' when your core HasKleisli
class WeaveAll mantle core where Source #
Methods
weaveAll :: (forall lbl eff. lbl -> eff :-> core) -> LooseRope mantle core :-> core Source #
Weaves all the remaining strands in the core, provided a polymorphic-enough interpretation function can be provided.
This function is notably useful to implement the "Rope-in-Rope" pattern,
when a Rope (possibly wrapped in Cayley) is used as the code for
another Rope. weaveAll in that case permits to transfer all the effects
of the outer Rope to the core Rope.
retwine :: RetwinableAs r strands core strands' => Rope r strands core :-> Rope r strands' core Source #
Predicates
type AnyRopeWith strands coreConstraints a b = forall mantle r core. (Rope r mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => Rope r mantle core a b Source #
A AnyRopeWith strands costraints is a Rope with contains the strands
in the variable strands , and whose core effect obeys the constraints in
the contraints variable.
type TightRopeWith strands coreConstraints a b = forall mantle core. (TightRope mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => TightRope mantle core a b Source #
type LooseRopeWith strands coreConstraints a b = forall mantle core. (LooseRope mantle core `Entwines` strands, core `SatisfiesAll` coreConstraints) => LooseRope mantle core a b Source #
type family Entwines rope (strands :: [Strand]) :: Constraint where ... Source #
Tells whether a collection of strands is in a Rope.
Equations
| Entwines rope '[] = () | |
| Entwines rope ('(name, eff) ': strands) = (InRope name eff rope, rope `Entwines` strands) |
type family SatisfiesAll (x :: k) (csts :: [k -> Constraint]) :: Constraint where ... Source #
Tells whether a type satisfies all the given constraints.
Equations
| SatisfiesAll x '[] = () | |
| SatisfiesAll x (c1 ': cnsts) = (c1 x, x `SatisfiesAll` cnsts) |
Reexports
type (:->) (p :: k -> k1 -> Type) (q :: k -> k1 -> Type) = forall (a :: k) (b :: k1). p a b -> q a b infixr 0 #
(:->) has a polymorphic kind since 5.6.
Proxy for label type