haskpy.typeclasses.cocartesian.Cocartesian

Cocartesian

class Cocartesian

Bases: Profunctor

Cocartesian profunctor

Perhaps better known as Choice in Haskell:

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

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

Minimal complete definition: left | right.

__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

flap(x)

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

left()[source]
map(g)

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

replace(x)

Haskell ($>) operator

right()[source]