A typeclass is a specification for one behavior associated with a single type. This behavior is checked by a test suite called the “laws” for that typeclass. These test suites are available in the package arrow-tests.
What differentiates typeclasses from regular OOP inheritance is that typeclasses are meant to be implemented outside of their types. The association is done using generic parametrization rather than the usual subclassing by implementing the interface. This means that they can be implemented for any class, even those not in the current project, and allows us to make available at the global scope any one implementation of a typeclasses for the single unique type they’re associated with.
You can read all about how Arrow does typeclasses in the glossary.
We will list all the typeclasses available in arrow by the module they belong to, and a short description of the behavior they abstract.
The package typeclasses contains all the typeclass definitions that are general enough not to be part of a specialized package. We will list them by their hierarchy.
Inject - transformation between datatypes
Alternative - has an structure that contains either of two values
Show- literal representation of an object
Functor - its contents can be mapped
Applicative - independent execution
ApplicativeError - recover from errors in independent execution
Monad - sequential execution
MonadError - recover from errors in sequential execution
Comonad - can extract values from it
Bimonad - both monad and comonad
Semigroup - can combine two objects together
SemigroupK - can combine two datatypes together
Monoid - combinable objects have an empty value
MonoidK - datatypes have an empty value
Foldable - has a structure from which a value can be computed from visiting each element
Bifoldable - same as foldable, but for structures with more than one possible type, like either
Reducible - structures that can be combined to a summary value
Traverse - has a structure for which each element can be visited and get applied an effect
Effects provides a hierarchy of typeclasses for lazy and asynchronous execution.
MonadSuspend - can evaluate functions lazily
Async - can be created using an asynchronous callback function
Effect - can extract a value from an asynchronous function
The Monad Template Library module gives more specialized version of existing typeclasses
FunctorFilter - can map values that pass a predicate
MonadFilter - can sequentially execute values that pass a predicate
TraverseFilter - can traverse values that pass a predicate
MonadCombine - has a structure that can be combined and split for several datatypes