klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Functor #74

Open klequis opened 2 years ago

klequis commented 2 years ago

Haskell's Functor class implements the functor laws.

fmap id      = id              -- identity
fmap (f . g) = fmap f . fmap g -- composition

These laws ensure that the containers shape is unchanged by fmap and that the container's contents are not re-arranged by the mapping operation.

source: https://www.haskell.org/tutorial/monads.html

klequis commented 2 years ago

In mathematics/category theory, a functor is a mapping between categories.

The set must have an identity and be composable.

image for every object X in C (identity morphisms).

image for all morphisms f:X -> Y and g:Y -> Z in C (composition)

source: wikipedia

klequis commented 2 years ago

unknown source

Rules of functor

  1. Mapping the composition of two arrows is the same as composing the mapping of the fst arrow and the mapping of the 2nd arrow

image

  1. The mapping of an objects identity is the same as the identity of the objects mapping.

image