haskpy.typeclasses.functor.Functor

Functor

class Functor

Bases: Type

Covariant functor

Minimal complete definition:

map

Functor laws:

  • Identity: map(identity) == identity

  • Composition: map(compose(f, g)) == compose(map(f), map(g))

For property tests:

sample_functor_type_constructor

Examples

In Haskell, Map is a Functor, but not Applicative

__rpow__(f)[source]

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.

flap(x)[source]

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

map(f)[source]

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

replace(x)[source]

Haskell ($>) operator