Description
Subcategories induced by class constraints.
Description
Please see the README on GitHub at https://github.com/konn/subcategories#readme
README.md
The subcategories package
This package provides variants of functor-like structures, with domain types are constrained. In particular, this package provides an abstraction for functorial containers, which can be expressed as a functor from a full-subcategory of Hask to Hask itself [^1].
For example:
- We can treat
Setas if it is aFuctor,Foldable,Applicative, with their domain restricted to full-subcategory Ord ofOrdinstances of Hask. - For
MonoFoldableorMonoTraversabletypes (frommono-traversablepackage), we provideWrapMonowrapper with zero-cost coercion. Suchmonos can be regarded as a functorial structure from the full subcategory consisting of just a single object, sayElement mono.
[^1]: Strictly speaking, CFoldable, a constrained counterpart of Foldable, doesn't require a functoriality as with the original Foldable.
Optimisation
This library is designed to keep the abstraction runtime overhead as minimum as possible.
Some notes:
- If a constrained term such as
cmaporczipWithhas concrete type, it must have exactly the same representation as the corresponding operation modulo (zero-cost) coercion.- The same still holds if the set of required constraints coincides.
- Although the constructor of
WrapMono mono ais hidden, its just anewtype-wrapper aroundmono; hence, constrained operators must have the same representations as the corresponding combinators inmono-traversablepackage.
- OTOH, for a polymorphic term, like
cmap :: (Ord a, Ord b) => (a -> b) Set a -> Set bandSet.map, they can have different representations; indeed,Set.mapdoesn't requireato beOrd-instance and therefore the implementation ofcmapdiscards the dictionary forOrd ato callSet.map.