haskpy.typeclasses.profunctor.Profunctor

Profunctor

class Profunctor

Bases: Functor, Contravariant

Minimal complete definition: dimap | (contramap & map).

Instead of using lmap and rmap as in Haskell, let’s use the already introduced contramap and map.

__rpow__(f)

Lifting operator ** lifts similarly as <$> in Haskell

f ** x translates to x.map(f) and map(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.

contramap(f)[source]

(a -> b) -> p b c -> p a c

contrareplace(x)

f b -> b -> f a

dimap(f, g)[source]

p b c -> (a -> b) -> (c -> d) -> p a d

flap(x)

Functor f => f (a -> b) -> a - > f b

map(g)[source]

(b -> c) -> p a b -> p a c

replace(x)

Haskell ($>) operator