Copyright | (c) Paweł Nowak |
---|---|
License | MIT |
Maintainer | Paweł Nowak <pawel834@gmail.com> |
Stability | experimental |
Safe Haskell | None |
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.
- class SemiIsoFunctor f where
- (/$/) :: SemiIsoFunctor f => ASemiIso' a b -> f b -> f a
- (/$~) :: (SemiIsoFunctor f, HFoldable b', HFoldable b, HUnfoldable b', HUnfoldable b, Rep b' ~ Rep b) => ASemiIso' a b' -> f b -> f a
- (~$/) :: (SemiIsoFunctor f, HFoldable a', HFoldable a, HUnfoldable a', HUnfoldable a, Rep a' ~ Rep a) => ASemiIso' a' b -> f b -> f a
- (~$~) :: (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
- class SemiIsoFunctor f => SemiIsoApply f where
- class SemiIsoApply f => SemiIsoAlternative f where
- class SemiIsoApply m => SemiIsoMonad m where
- class SemiIsoMonad m => SemiIsoFix m 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
.
(/$~) :: (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)
class SemiIsoApply f => SemiIsoAlternative f where Source
Equivalent of Alternative
for SemiIsoFunctor
.
f a
should form a monoid with identity siempty
and binary
operation /|/
.
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
.
class SemiIsoMonad m => SemiIsoFix m where Source
A SemiIsoMonad with fixed point operator.
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
.