Copyright | (c) Paweł Nowak |
---|---|
License | MIT |
Maintainer | Paweł Nowak <pawel834@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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 :)
- class SemiIsoFunctor f where
- (/$/) :: SemiIsoFunctor f => ASemiIso' a b -> f b -> f a
- class SemiIsoFunctor f => SemiIsoApply f where
- class SemiIsoApply f => SemiIsoAlternative f where
- sisequence :: SemiIsoApply f => [f a] -> f [a]
- sireplicate :: SemiIsoApply f => Int -> f a -> f [a]
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
(/$/) :: 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)
class SemiIsoApply f => SemiIsoAlternative f where Source
Equivalent of Alternative
for SemiIsoFunctor
.
f a
should form a monoid with identity siempty
and binary
operation /|/
.
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
.