Safe Haskell | None |
---|
- data Iso w m a b = Iso {}
- inverseI :: (Monad m, Monad w) => Iso w m a b -> Iso m w b a
- type :<-> a b = Iso Identity Identity a b
- iso :: (Monad m, Monad w) => (a -> b) -> (b -> a) -> Iso w m a b
- ($-) :: (a :<-> b) -> a -> b
- (-$) :: (a :<-> b) -> b -> a
- newtype IsoPure a b = IsoPure {}
- ifmap :: (Monad w, Monad m, Functor f IsoPure IsoPure) => Iso Identity Identity a b -> Iso w m (f a) (f b)
- fromPure :: (Monad w, Monad m) => IsoPure a b -> Iso w m a b
- wordsI :: (Monad m, Monad w) => Iso w m String [String]
- showI :: (Read s, Show s, Monad w, Monad m) => Iso w m s String
- linesI :: (Monad m, Monad w) => Iso w m String [String]
- curryI :: (Monad m, Monad w) => Iso w m ((a, b) -> c) (a -> b -> c)
- enumI :: (Enum a, Monad m, Monad w) => Iso w m Int a
- integerI :: (Integral a, Monad m, Monad w) => Iso w m a Integer
- rationalI :: (Real a, Fractional a, Monad m, Monad w) => Iso w m a Rational
- zipI :: (Monad m, Monad w) => Iso w m ([a], [b]) [(a, b)]
- incrementI :: (Monad m, Monad w, Num a) => Iso w m a a
- incrementByI :: (Monad m, Monad w, Num a) => a -> Iso w m a a
- consI :: (Monad m, Monad w) => Iso w m (a, [a]) [a]
- distributeI :: (Monad m, Monad w) => Iso w m (a, Either b c) (Either (a, b) (a, c))
- factorI :: (Monad m, Monad w) => Iso w m (Either (a, b) (a, c)) (a, Either b c)
- type :<~> a b = Iso Maybe Maybe a b
Documentation
Iso is similar but more flexible than Lens in that they have no dependency on
context. This flexibility affords a number of nice class instances that we
don't get with Lens, so these can be quite useful in combination. See isoL
for converting to Lens
.
A less imprecise name for the code here might be Bijection
but no one wants
to type that.
An Isomorphism or one-to-one mapping between types. These are very similar
to a Lens
, but are not dependent on context, making them more flexible. The
functions also alow a Monadic context, supporting partial isomorphisms, and
other interesting functionality.
Monad m => Functor m (Iso m m) (Iso Identity Identity) | |
(Monad m, Monad w) => PFunctor Either (Iso w m) (Iso w m) | |
(Monad m, Monad w) => PFunctor (,) (Iso w m) (Iso w m) | |
(Monad m, Monad w) => QFunctor Either (Iso w m) (Iso w m) | |
(Monad m, Monad w) => QFunctor (,) (Iso w m) (Iso w m) | |
(Monad m, Monad w) => Bifunctor Either (Iso w m) (Iso w m) (Iso w m) | |
(Monad m, Monad w) => Bifunctor (,) (Iso w m) (Iso w m) (Iso w m) | |
(Monad m, Monad w) => Category (Iso w m) | |
(Monad m, Monad w) => Braided (Iso w m) Either | |
(Monad m, Monad w) => Braided (Iso w m) (,) | |
(Monad m, Monad w) => Symmetric (Iso w m) Either | |
(Monad m, Monad w) => Symmetric (Iso w m) (,) | |
(Monad m, Monad w) => Monoidal (Iso w m) (,) | |
(Monad m, Monad w) => Comonoidal (Iso w m) (,) | |
(Monad m, Monad w) => Associative (Iso w m) Either | |
(Monad m, Monad w) => Associative (Iso w m) (,) | |
(Monad m, Monad w) => Disassociative (Iso w m) Either | |
(Monad m, Monad w) => Disassociative (Iso w m) (,) |
Convenient Iso types
Pure isomorphisms
Wrapped pure Iso
A wrapper for a more (->)
-like Functor instances
ifmap :: (Monad w, Monad m, Functor f IsoPure IsoPure) => Iso Identity Identity a b -> Iso w m (f a) (f b)Source
fromPure :: (Monad w, Monad m) => IsoPure a b -> Iso w m a bSource
Unwrap and make polymorphic an IsoPure
Pre-defined isomorphisms
Note: while all of these are pure and could be expressed as '(:-)', we
define them polymorphically in Monad
for maximum flexibility in
composing with other Lens
or Iso
.
Also note that for most of these apply i . unapply i
is not strictly
id
for the entire input domain, e.g. zipI
obviously truncates lists of
differing length, etc.