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

Copyright(c) Paweł Nowak
LicenseMIT
MaintainerPaweł Nowak <pawel834@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
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.

Operator names are up to bikeshedding :)

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.

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

sipure, (/*/)

Methods

sipure :: 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

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.