Natural transformations
Natural transformations are operations that transform the structure of a type. If Functor is
structure preserving then natural-transformations are structure transforming.
A concrete example is that if we call Map on a Seq〈A〉, then the structure (the Seq) is
preserved, but the values within the structure, A, are transformed: and that defines a Functor,
whereas with natural-transformations we could call AsEnumerable() on the Seq〈A〉. The result
would preserve value-type, A, but transform the structure Seq to IEnumerable.
This common pattern of structure transformation is a natural-transformation. It is captured by the type Natural〈F, G〉.
Natural
Natural〈F, G〉 defines a single method, Transform, that maps a K<F, A> to a K<G, A>. This could be K<Try, A>
to K<Option, A> for example.
CoNatural
There is also CoNatural〈F, G〉 which is the dual of Natural〈F, G〉. It has the Transform arrow reversed, which
means it maps a K<G, A> to a K<F, A>.
It is functionally exactly the same as Natural. The reason it exists is listed below.
NaturalIso
A natural-isomorphism (NaturalIso〈F, G〉) is a natural-transformation that can map forwards and backwards:
F〈A〉-> G〈A〉
And the dual:
G〈A〉-> F〈A〉
NaturalIso derives from:
Natural〈F, G〉
CoNatural〈F, G〉
The reason it doesn't derive from
Natural〈F, G〉andNatural〈G, F〉is because C# can't type-check whenF == Gand so the dual needs a separate type:CoNatural〈F, G〉.
NaturalMono
A natural monomorphic transformation means there's one arrow between F and G. Therefore, there's also a CoNatural
between G and F (CoNatural is the dual of Natural, so its arrows are flipped, so a CoNatural between G and F
is isomorphic to a Natural between F and G).
NaturalMono derives from:
Natural〈F, G〉
CoNatural〈G, F〉
The CoTransform method has a default implementation.
NaturalEpi
An epimorphism is the dual of a monomorphism. So, NaturalEpi is the dual of NaturalMono.
NaturalEpi derives from:
Natural〈G, F〉
CoNatural〈F, G〉
The Transform method has a default implementation.
Contents
interface CoNatural <in F, out G> Source #
Natural transformation
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | From functor |
| type | G | To functor |
Methods
method K<F, A> CoTransform <A> (K<G, A> fa) Source #
Perform a natural transformation from FA -> GA
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | A | Bound value type |
| param | fa | Functor to transform |
| returns | Transformed functor | |
Methods
method K<F, A> transform <F, G, A> (K<G, A> fa) Source #
Co-natural transformation
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | Source functor type |
| type | G | Target functor type |
| type | A | Bound value type |
| param | fa | Functor to transform |
| returns | Transformed functor | |
interface Natural <out F, in G> Source #
Natural transformation
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | From functor |
| type | G | To functor |
Methods
method K<G, A> Transform <A> (K<F, A> fa) Source #
Perform a natural transformation from FA -> GA
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | A | Bound value type |
| param | fa | Functor to transform |
| returns | Transformed functor | |
Methods
method K<G, A> transform <F, G, A> (K<F, A> fa) Source #
Natural transformation
If functor map operations transform the bound-values within the structure, then
natural-transformations transform the structure itself.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | Source functor type |
| type | G | Target functor type |
| type | A | Bound value type |
| param | fa | Functor to transform |
| returns | Transformed functor | |
interface NaturalEpi <in F, out G> Source #
Natural epimorphic transformation
Epimorphism is the dual of monomorphism. So, NaturalEpi is the dual of NaturalMono.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | From functor |
| type | G | To functor |
interface NaturalIso <F, G> Source #
Natural isomorphism
Parameters
| type | F | Functor |
| type | G | Functor |
interface NaturalMono <out F, in G> Source #
Natural monomorphic transformation
Monomorphism means that there's one arrow between F and G. Therefore, there's also a CoNatural between
G and F (CoNatural is the dual of Natural, so its arrows are flipped, so a CoNatural between G and F
is isomorphic to a Natural between F and G). That's why NaturalMono derives from both Natural and
CoNatural and can provide a default implementation for CoTransform.
This type wouldn't need to exist is C# was better at type-unification. Use this when you want a unidirectional
natural-transformation. Use NaturalIso when you want a bidirectional natural-transformation.
Functors are referenced, because that's the true definition in category-theory, but there is no requirement in language-ext for FA or GA to be functors. It is just typically true that FA and GA will also be functors.
Parameters
| type | F | From functor |
| type | G | To functor |