haskpy.typeclasses.cartesian.Cartesian

Cartesian

class Cartesian

Bases: Profunctor

Cartesian profunctor

Perhaps better known as Strong in Haskell:

https://hackage.haskell.org/package/profunctors-5.2/docs/Data-Profunctor-Strong.html

I decided to use name Cartesian because that was used in the profunctor optics paper.

Minimal complete definition: first | second.

__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)

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

contrareplace(x)

f b -> b -> f a

dimap(f, g)

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

first()[source]

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

flap(x)

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

map(g)

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

replace(x)

Haskell ($>) operator

second()[source]

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