Copyright | (c) Tristan Wibberley 2017 |
---|---|
License | GPL-2 |
Maintainer | tristan.wibberley@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Here is a longer description of this module, containing some
commentary with some markup
.
- points :: (Functor f, Alternative g) => (a -> Bool) -> f a -> Compose f g a
- reveal :: (Functor f, Applicative g) => f a -> Compose f g a
- flatten :: Applicative f => f a -> Compose f Maybe a -> f a
- (<-$>) :: Functor f => (g a -> h a) -> Compose f g a -> Compose f h a
- universal :: Functor f => (g a -> h a) -> Compose * * f g a -> Compose * * f h a
- (<-|>) :: (Applicative f, Alternative g) => Compose * * f g a -> Compose * * f g a -> Compose * * f g a
- class (Applicative g, Applicative h) => Superposition g h where
- simplify :: Superposition g h => g a -> Maybe (h a)
- collapse :: Superposition g h => (a -> a -> a) -> g a -> h a
- keep :: Alternative f => (a -> Bool) -> a -> f a
- keepIdentity :: Alternative f => (a -> Bool) -> Identity a -> f a
Constructors
:: (Functor f, Alternative g) | |
=> (a -> Bool) | A predicate that indicates whether a point is occupied by its original value or vacant. |
-> f a | The seed points with their values. |
-> Compose f g a | The constructed |
Turns a container of values to a container of either retained or destroyed values based on a predicate
The type constraint allows us to model possible outcomes so destroyed values are just "no possible outcomes" while retained values represent "the only possible outcome".
To represent that "no value" is a possible outcome, a
should be some type like (
) or (Maybe
a
).Either
String
a
f
- This
Functor
defines the broad scale behaviours but itsAlternative
instance is overridden. This in particular might change during upcoming design validation. g
- This
Functor
supplies the supercedentAlternative
instance and thus the finer behaviours.
:: (Functor f, Applicative g) | |
=> f a | Initial flat structure |
-> Compose f g a | enhanced structure, albeit with no changes |
Converts a functor so that each point at the source has alternatives.
It's just like Compose but the applicative instance appends new alternative values in the rightmost (inner/minor) functor instead of in the leftmost (outer/major) functor.
The result is that two
s of alternatives zip together,
providing alternatives to each point.ZipList
Given the immediate utility of this, I do wonder if the
instance of Alternative
is the wrong one.Compose
f
- The major functor, overall mapping/view
g
- This has a a few key useful interpretations depending on its instances, examples below.
a
- Transformed/contained value type.
Some example instances that you might want to rely on from g
:
Alternative
- Superposition functor.
- How do individual items have a set of possible values?
- How do those possible values collapse to form one optional value?
- etc.
- etc
- There are a lot of other utilities for this type.
Provides structure for values at the other end of a Functor
Destructors
:: Applicative f | |
=> f a | Default values |
-> Compose f Maybe a | Structured container |
-> f a | Destructured container |
If the type constructor of the possibilities concept is
then you can use Maybe
to provide default values for
impossible points.flatten
NOTE: This uses the applicative instance of the broad scale
which means exact behaviour can vary depending on the type ofFunctor
because each has a different technique to ensure a value is found for every point:Applicative
flist of a
- Cross-product; Providing all default values once for all points.
ZipList
a- zipWith; Providing one default value for each point until there are either no defaults remaining or no more points.
Identity
a- One default must surely be provided and it is used if a default is required.
Maybe
a- Not sure exactly what this does, TBC.
Either
a- Not sure exactly what this does, TBC.
Restructors
(<-$>) :: Functor f => (g a -> h a) -> Compose f g a -> Compose f h a Source #
fmap below the zeropoint
universal :: Functor f => (g a -> h a) -> Compose * * f g a -> Compose * * f h a Source #
fmap below the zeropoint, function variant of <-$>
operator
(<-|>) :: (Applicative f, Alternative g) => Compose * * f g a -> Compose * * f g a -> Compose * * f g a Source #
Alternative below the zeropoint
class (Applicative g, Applicative h) => Superposition g h where Source #
collapse f empty = simplify empty
collapse f (pure x) = simplify (pure x)
collapse f (x <|> y) = pure (f x y)
g
must form a monoid under f
when
is the monoid's identity.empty
Alternative h => Superposition [] h Source # | Superposition within a nondeterminism list (ie, [])
This is roughly the same as
|
(Applicative f, Superposition g h) => Superposition (Compose * * f g) (Compose * * f h) Source # | Superposition within |
simplify :: Superposition g h => g a -> Maybe (h a) Source #
Tries to convert from one alternative to another
collapse :: Superposition g h => (a -> a -> a) -> g a -> h a Source #
Instructors
keep :: Alternative f => (a -> Bool) -> a -> f a Source #
Turns a value "a
" to
or Just
a
based on a predicate assuming you use it in a
context that wants Nothing
instead of some other representation of Maybe
a
sAlternative
keepIdentity :: Alternative f => (a -> Bool) -> Identity a -> f a Source #