- haskpy.typeclasses.apply_.Apply
Apply¶
- class Apply¶
Bases:
Functor
Apply typeclass
Apply
is toApplicative
asSemigroup
is toMonoid
.Minimal complete definition:
map | (apply | apply_to)
Why do we need
Apply
in addition toApplicative
? For instance,Dictionary
is an instance ofApply
but notApplicative
.References
- __matmul__(x)[source]¶
Application operand
@
applies similarly as<*>
in Haskellf @ x
translates tof.apply_to(x)
,x.apply(f)
andapply(f, x)
.Why
@
operator?It’s not typically used as often as some other more common operators so less risk for confusion.
The operator is not a commutative as isn’t
apply
either.If we see matrix as some structure, then matrix multiplication takes both left and right operand inside this structure and gives a result also inside this structure, similarly as
apply
does. So it’s an operator for two operands having a similar structure.The operator evaluates the contained function(s) at the contained value(s). Thus,
f
“at”x
makes perfect sense.
- __rpow__(f)¶
Lifting operator
**
lifts similarly as<$>
in Haskellf ** x
translates tox.map(f)
andmap(f, x)
.Why
**
operator?It’s not typically used as often as multiplication or addition so less risk of confusion.
It’s not commutative operator as isn’t lifting either.
The two operands have very different roles. They are not at the same “level”.
The right operand is “higher”, that is, it’s inside a structure and the left operand is kind of “raised to the power” of the second operand, where the “power” is the functorial structure.
The same operand is also used for function composition because function composition is just mapping. Visually the symbol can be seen as chaining two stars similarly as function composition chains two functions.
- apply_first(x)[source]¶
Combine two actions, keeping only the result of the first
Apply f => f a -> f b -> f a
- apply_second(x)[source]¶
Combine two actions, keeping only the result of the second
Apply f => f a -> f b -> f b
- flap(x)¶
Functor f => f (a -> b) -> a - > f b
- map(f)¶
Functor f => f a -> (a -> b) -> f b
- replace(x)¶
Haskell ($>) operator