- haskpy.typeclasses.profunctor.Profunctor
Profunctor¶
- class Profunctor¶
Bases:
Functor
,Contravariant
Minimal complete definition:
dimap | (contramap & map)
.Instead of using
lmap
andrmap
as in Haskell, let’s use the already introducedcontramap
andmap
.- __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.
- contrareplace(x)¶
f b -> b -> f a
- flap(x)¶
Functor f => f (a -> b) -> a - > f b
- replace(x)¶
Haskell ($>) operator