lens-1.5: Lenses, Folds and Traversals

MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellSafe-Infered







class Category k => Isomorphic k whereSource

Used to provide overloading of isomorphism application

This is a Category with a canonical mapping to it from the category of isomorphisms over Haskell types.


isomorphic :: (a -> b) -> (b -> a) -> k a bSource

Build this morphism out of an isomorphism

The intention is that by using isomorphic, you can supply both halves of an isomorphism, but k can be instantiated to (->), so you can freely use the resulting isomorphism as a function.

isomap :: ((a -> b) -> c -> d) -> ((b -> a) -> d -> c) -> k a b -> k c dSource

Map a morphism in the target category using an isomorphism between morphisms in Hask.

data Isomorphism a b Source

A concrete data type for isomorphisms.

This lets you place an isomorphism inside a container without using ImpredicativeTypes.


Isomorphism (a -> b) (b -> a) 

iso :: (Isomorphic k, Functor f) => (a -> b) -> (b -> a) -> k (b -> f b) (a -> f a)Source

Build a simple isomorphism from a pair of inverse functions

 iso :: (a -> b) -> (b -> a) -> Simple Iso a b

isos :: (Isomorphic k, Functor f) => (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> k (c -> f d) (a -> f b)Source

Build an isomorphism family from two pairs of inverse functions

 isos :: (a -> c) -> (c -> a) -> (b -> d) -> (d -> b) -> Iso a b c d

from :: Isomorphic k => Isomorphism a b -> k b aSource

Invert an isomorphism.

Note to compose an isomorphism and receive an isomorphism in turn you'll need to use Category

 from (from l) = l

If you imported 'Control.Category.(.)', then:

 from l . from r = from (r . l)
 from :: (a :~> b) -> (b :~> a)

via :: Isomorphic k => Isomorphism a b -> k a bSource

 via :: Isomorphism a b -> (a :~> b)

type Iso a b c d = forall k f. (Isomorphic k, Functor f) => k (c -> f d) (a -> f b)Source

Isomorphim families can be composed with other lenses using either' (.)' and id from the Prelude or from Control.Category. However, if you compose them with each other using '(.)' from the Prelude, they will be dumbed down to a mere Lens.

 import Control.Category
 import Prelude hiding ((.),id)
 type Iso a b c d = forall k f. (Isomorphic k, Functor f) => Overloaded k f a b c d

type SimpleIso a b = Iso a a b bSource

 type SimpleIso a b = Simple Iso a b

_const :: Iso a b (Const a c) (Const b d)Source

This isomorphism can be used to wrap or unwrap a value in Const

 x^._const = Const x
 Const x^.from _const = x

identity :: Iso a b (Identity a) (Identity b)Source

This isomorphism can be used to wrap or unwrap a value in Identity.

 x^.identity = Identity x
 Identity x^.from identity = x