semi-iso-0.4.0.0: Weakened partial isomorphisms that work with lenses.

Copyright(c) Paweł Nowak
LicenseMIT
MaintainerPaweł Nowak <pawel834@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.SemiIsoFunctor

Description

Defines a functor from the category of semi-isomoprihsms to Hask.

The most interesting property of that class is that it can be instantiated by both covariant (like Parser) and contravariant (like Printer) functors. Therefore it can be used as a common interface to unify parsing and pretty printing.

Synopsis

Documentation

class SemiIsoFunctor f where Source

A functor from the category of semi-isomorphisms to Hask.

It is both covariant and contravariant in its single arugment.

The contravariant map is used by default to provide compatibility with Prisms (otherwise you would have to reverse them in most cases).

Instances should satisfy laws:

simap id      = id
simap (f . g) = simap g . simap f
simap         = simapCo . fromSemi
simapCo       = simap   . fromSemi

Minimal complete definition

simap | simapCo

Methods

simap :: ASemiIso' a b -> f b -> f a Source

The contravariant map.

simapCo :: ASemiIso' a b -> f a -> f b Source

The covariant map.

(/$/) :: SemiIsoFunctor f => ASemiIso' a b -> f b -> f a infixl 4 Source

A infix operator for simap.

(/$~) :: (SemiIsoFunctor f, HFoldable b', HFoldable b, HUnfoldable b', HUnfoldable b, Rep b' ~ Rep b) => ASemiIso' a b' -> f b -> f a infixl 4 Source

ai /$~ f = ai . morphed /$/ f

This operator handles all the hairy stuff with uncurried application: it reassociates the argument tuple and removes unnecessary (or adds necessary) units to match the function type. You don't have to use /* and */ with this operator.

(~$/) :: (SemiIsoFunctor f, HFoldable a', HFoldable a, HUnfoldable a', HUnfoldable a, Rep a' ~ Rep a) => ASemiIso' a' b -> f b -> f a infixl 4 Source

ai ~$/ f = morphed . ai /$/ f

(~$~) :: (SemiIsoFunctor f, HFoldable a, HUnfoldable a, HFoldable b, HUnfoldable b, HFoldable b', HUnfoldable b', Rep b' ~ Rep b, Rep b' ~ Rep a) => ASemiIso b' b' b' b' -> f b -> f a infixl 4 Source

ai ~$~ f = morphed . ai . morphed /$/ f

class SemiIsoFunctor f => SemiIsoApply f where Source

Equivalent of Applicative for SemiIsoFunctor.

However, this class implements uncurried application, unlike Applicative which gives you curried application.

Instances should satisfy laws:

TODO (they should be fine)

Minimal complete definition

(siunit | sipure), (/*/)

Methods

siunit :: f () Source

sipure :: ASemiIso' a () -> f a Source

sipureCo :: ASemiIso' () a -> f a Source

(/*/) :: f a -> f b -> f (a, b) infixl 5 Source

(/*) :: f a -> f () -> f a infixl 5 Source

(*/) :: f () -> f b -> f b infixl 5 Source

class SemiIsoApply f => SemiIsoAlternative f where Source

Equivalent of Alternative for SemiIsoFunctor.

f a should form a monoid with identity siempty and binary operation /|/.

Minimal complete definition

siempty, (/|/)

Methods

siempty :: f a Source

(/|/) :: f a -> f a -> f a infixl 3 Source

sisome :: f a -> f [a] Source

simany :: f a -> f [a] Source

class SemiIsoApply m => SemiIsoMonad m where Source

An analogue of Monad for SemiIsoFunctor.

Because of the 'no throwing away' rule bind has to "return" both a and b.

Minimal complete definition

(//=) | (=//)

Methods

(//=) :: m a -> (a -> m b) -> m (a, b) infixl 1 Source

(=//) :: (b -> m a) -> m b -> m (a, b) infixr 1 Source

class SemiIsoMonad m => SemiIsoFix m where Source

A SemiIsoMonad with fixed point operator.

Minimal complete definition

sifix | (=//=)

Methods

sifix :: (a -> m a) -> m a Source

(=//=) :: (a -> m b) -> (b -> m a) -> m (a, b) Source

Fixed point combined with bind, it's so symmetric!

sisequence :: SemiIsoApply f => [f a] -> f [a] Source

Equivalent of sequence.

Note that it is not possible to write sequence_, because you cannot void a SemiIsoFunctor.

sireplicate :: SemiIsoApply f => Int -> f a -> f [a] Source

Equivalent of replicateM.