Safe Haskell | None |
---|---|

Language | Haskell2010 |

A *natural transformation* is a concept from category theory for a mapping between two functors and their objects
that preserves a naturality condition. In Haskell the naturality condition boils down to parametricity, so a
natural transformation between two functors `f`

and `g`

is represented as

type NaturalTransformation f g = ∀a. f a → g a

This type appears in several Haskell libraries, most obviously in
natural-transformations. There are times, however,
when we crave more control. Sometimes what we want to do depends on which type `a`

is hiding in that `f a`

we're
given. Sometimes, in other words, we need an *unnatural* transformation.

This means we have to abandon parametricity for ad-hoc polymorphism, and that means type classes. There are two steps to defining a transformation:

- an instance of the base class
`Transformation`

declares the two functors being mapped, much like a function type signature, - while the actual mapping of values is performed by an arbitrary number of instances of the method
`$`

, a bit like multiple equation clauses that make up a single function definition.

The module is meant to be imported qualified.

# Documentation

class Transformation t Source #

A `Transformation`

, natural or not, maps one functor to another.

#### Instances

(Transformation t1, Transformation t2, Domain t1 ~ Domain t2) => Transformation (Either t1 t2) Source # | |

(Transformation t1, Transformation t2, Domain t1 ~ Domain t2) => Transformation (t1, t2) Source # | |

(Transformation t, Transformation u, Domain t ~ Codomain u) => Transformation (Compose t u) Source # | |

Transformation (Fold p m) Source # | |

Transformation (Map p q) Source # | |

Transformation (Traversal p q m) Source # | |

Transformation (Arrow p q x) Source # | |

class Transformation t => At t x where Source #

An unnatural `Transformation`

can behave differently at different points.

#### Instances

(At t x, At u x, Domain t ~ Domain u) => At (Either t u) x Source # | |

(At t x, At u x, Domain t ~ Domain u) => At (t, u) x Source # | |

(At t x, At u x, Domain t ~ Codomain u) => At (Compose t u) x Source # | |

At (Fold p m) x Source # | |

At (Map p q) x Source # | |

At (Traversal p q m) x Source # | |

At (Arrow p q x) x Source # | |

Composition of two transformations

Compose t u |