Copyright | (c) 2015, Peter Trško |
---|---|

License | BSD3 |

Maintainer | peter.trsko@gmail.com |

Stability | experimental |

Portability | NoImplicitPrelude |

Safe Haskell | Safe |

Language | Haskell98 |

This module defines types that behave as a precursors to types defined in lens library.

*Since version 0.11.0.0.*

- type PreIso r s t a b = ((b -> t) -> (s -> a) -> r) -> r
- type PreIso' r s a = PreIso r s s a a
- type PreLens r s t a b = ((b -> s -> t) -> (s -> a) -> r) -> r
- type PreLens' r s a = PreLens r s s a a
- type PrePrism r s t a b = ((b -> t) -> (s -> Either t a) -> r) -> r
- type PrePrism' r s a = PrePrism r s s a a

# PreIso

type PreIso r s t a b = ((b -> t) -> (s -> a) -> r) -> r Source

Family of types that can construct isomorphism between types.

*Since version 0.11.0.0.*

# PreLens

type PreLens' r s a = PreLens r s s a a Source

A simple `PreLens`

, where we can not change the type of the information
we are focusing on. As a consequence neither the type of the container data
type can be changed.

*Since version 0.11.0.0.*

# PrePrism

type PrePrism r s t a b = ((b -> t) -> (s -> Either t a) -> r) -> r Source

We can also get `PrePrism`

by specializing `PreIso`

:

`PrePrism`

r s t a b =`PreIso`

r s t (`Either`

t a) b

This fact is not surprising, since *Prisms* are actually a special case of
isomorphism between two types.

Let's have a type `s`

, and we want to extract specific information out of
it, but that information may not be there. Because of the fact that the type
`s`

can be a sum type. Imagine e.g. standard `Maybe`

data type:

`Maybe`

a =`Nothing`

|`Just`

a

How do we create something that can extrat that information from a sum type,
and if necessary, also reconstructs that sum type. The answer is *Prism*,
which is defined as an isomorphism between that type `s`

and

where `Either`

t a`a`

is the information we want to extract and `t`

is the rest that we
don't care about.

You may have noticed, that definition of `PrePrism`

contains some type
variables that aren't mentioned in the above definition. The reason for this
is that, as with *Lenses* we may want to extract value of type `a`

, but when
constructing new data type we may want to change the type of that value in
to `b`

and therefore type `s`

may not fit, which is the reason why we have
type `t`

in there. Once again we can ilustrate this with `Maybe`

. Lets say
that we have a value of `s = `

, but if we change the type of `Maybe`

a`a`

in
to `b`

, and try to create `Maybe`

again, then it would have type

.`Maybe`

b
= t

*Since version 0.11.0.0.*

type PrePrism' r s a = PrePrism r s s a a Source

A simple `PrePrism`

, where we can not change the type of the information
we are focusing on. As a consequence neither the type of the container data
type can be changed.

If we define `PrePrism'`

in terms of `PreIso'`

then we have even better
ilustration of *Prism* concept in terms of isomorphism:

`PrePrism'`

r s a =`PreIso'`

r s (`Either`

t a)

*Since version 0.11.0.0.*