The big idea is the notion of Equivalence (which is more "concrete" than the abstract notion of Equality, which is applicable only to abstract concepts, like Numbers.) and substitution of an equivalent for an equivalent

A rickshaw is a substitutio for a bus in the context of driving to a short distance, while a train is not a substitute for a bus in a context where there is no railways.

This is a step for a composeable, general logic, based on a predicate logic

This is the way to define what it takes to be a

to be Comparable is to have the eqivalence predicate implemented to be Orderable is to have less-than and eq implemented

to be Printable is to have the show method, similar to .toString or str

more abstract notions are of a Monoid and a Functor.

A functor is a transformation, a mapping from a domain to a range. Same input - same output. Always. It is a more general abstraction than a function, which is also a mapping from inputs to outputs. A transformation of values.

Functor generalizes what we call mapping, or application of a function to a value.

It is similar to what the map function does, given that one could apply a map not only to homogenous lists. A list is a merely generalization of an ordered sequence. A single value or even a zero value could be considered (put in the context) of a list, so mapping could be done over a single element or a zero value.

so, a functor is a transformation, a mapping. To be a functor is to implement fmap which conforms to the functor laws

functor laws guarantee that applying an identity function does not change anything, and that functors are composeable, which means that applying functor f and then functor g is the same as applying of a composition of (g . f) (f andThen g)

this means that mappings are composable

But why? In theory, to build a complex pipelines of transformers (transducers) and type-check that they are sound (will not blowup).

for example, a functor could be applied to a result of a function (transformer, like increment, decrement, square, etc or a compinator, like + or *) and such a function itself could be thought as a functor, but only it confirms to the functor laws.

in order to be composable (to form a pipeline) the domain and range must match. This is what the typeclasses are for - to impose some contracts (discipline) to a generic functions, which could be checked (enforced) at a compile time. This is what is behind all the hype.

Most of these generic anstractions, like a Monoid are useless, some, like Monad, are occasionally useful. Functors have its use too.

Last modified 2 years ago Last modified on Dec 25, 2017, 2:00:33 PM
Note: See TracWiki for help on using the wiki.