subzero-0.1.0.3: Helps when going "seed values" -> alternatives and optional -> answers

Control.Applicative.SubZero

Description

Here is a longer description of this module, containing some commentary with some markup.

Synopsis

# Documentation

data SubZero f g a Source #

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 ZipLists of alternatives zip together, providing alternatives to each point.

Given the immediate utility of this, I do wonder if the Alternative instance of Compose is the wrong one.

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.

Instances

 (Functor g, Functor f) => Functor (SubZero f g) Source # Methodsfmap :: (a -> b) -> SubZero f g a -> SubZero f g b #(<\$) :: a -> SubZero f g b -> SubZero f g a # (Applicative g, Applicative f) => Applicative (SubZero f g) Source # Methodspure :: a -> SubZero f g a #(<*>) :: SubZero f g (a -> b) -> SubZero f g a -> SubZero f g b #(*>) :: SubZero f g a -> SubZero f g b -> SubZero f g b #(<*) :: SubZero f g a -> SubZero f g b -> SubZero f g a # (Applicative f, Alternative g) => Alternative (SubZero f g) Source # Methodsempty :: SubZero f g a #(<|>) :: SubZero f g a -> SubZero f g a -> SubZero f g a #some :: SubZero f g a -> SubZero f g [a] #many :: SubZero f g a -> SubZero f g [a] # (Applicative f, Superposition g h) => Superposition (SubZero f g) (SubZero f h) Source # Superposition within SubZero * h Methodssimplify :: SubZero f g a -> Maybe (SubZero f h a) Source #collapse :: (a -> a -> a) -> SubZero f g a -> SubZero f h a Source # (Eq a, Eq1 g, Eq1 f) => Eq (SubZero f g a) Source # Methods(==) :: SubZero f g a -> SubZero f g a -> Bool #(/=) :: SubZero f g a -> SubZero f g a -> Bool # (Ord a, Ord1 g, Ord1 f) => Ord (SubZero f g a) Source # Methodscompare :: SubZero f g a -> SubZero f g a -> Ordering #(<) :: SubZero f g a -> SubZero f g a -> Bool #(<=) :: SubZero f g a -> SubZero f g a -> Bool #(>) :: SubZero f g a -> SubZero f g a -> Bool #(>=) :: SubZero f g a -> SubZero f g a -> Bool #max :: SubZero f g a -> SubZero f g a -> SubZero f g a #min :: SubZero f g a -> SubZero f g a -> SubZero f g a # (Read a, Read1 g, Read1 f) => Read (SubZero f g a) Source # MethodsreadsPrec :: Int -> ReadS (SubZero f g a) #readList :: ReadS [SubZero f g a] #readPrec :: ReadPrec (SubZero f g a) #readListPrec :: ReadPrec [SubZero f g a] # (Show a, Show1 g, Show1 f) => Show (SubZero f g a) Source # MethodsshowsPrec :: Int -> SubZero f g a -> ShowS #show :: SubZero f g a -> String #showList :: [SubZero f g a] -> ShowS #

# Constructors

Arguments

 :: (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. -> SubZero f g a The constructed SubZero value.

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 (Maybe a) or (Either String a).

f
This Functor defines the broad scale behaviours but its Alternative instance is overridden. This in particular might change during upcoming design validation.
g
This Functor supplies the supercedent Alternative instance and thus the finer behaviours.

Arguments

 :: (Functor f, Applicative g) => f a Initial flat structure -> SubZero f g a enhanced structure, albeit with no changes

Provides structure for values at the other end of a Functor

# Destructors

Arguments

 :: Applicative f => f a Default values -> SubZero f Maybe a Structured container -> f a Destructured container

If the type constructor of the possibilities concept is Maybe then you can use flatten to provide default values for impossible points.

• NOTE: This uses the applicative instance of the broad scale Functor which means exact behaviour can vary depending on the type of Applicative f because each has a different technique to ensure a value is found for every point:

list 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

class (Alternative g, Alternative 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 empty is the monoid's identity.

Minimal complete definition

Methods

simplify :: g a -> Maybe (h a) Source #

Tries to convert from one alternative to another

collapse :: (a -> a -> a) -> g a -> h a Source #

Combines many alternatives into one using a function parameter. empty stays empty. This is quite free in the type of the result so the user can choose whether to keep the same type to re-expand the structure or to transform to a smaller type to avoid relying on instances for certain behaviours.

Instances

 Alternative h => Superposition [] h Source # Superposition within a nondeterminism list (ie, []) Methodssimplify :: [a] -> Maybe (h a) Source #collapse :: (a -> a -> a) -> [a] -> h a Source # (Applicative f, Superposition g h) => Superposition (SubZero f g) (SubZero f h) Source # Superposition within SubZero * h Methodssimplify :: SubZero f g a -> Maybe (SubZero f h a) Source #collapse :: (a -> a -> a) -> SubZero f g a -> SubZero f h a Source #

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 #

Combines many alternatives into one using a function parameter. empty stays empty. This is quite free in the type of the result so the user can choose whether to keep the same type to re-expand the structure or to transform to a smaller type to avoid relying on instances for certain behaviours.

keep :: Alternative f => (a -> Bool) -> a -> f a Source #

Turns a value "a" to Just a or Nothing based on a predicate assuming you use it in a context that wants Maybe a instead of some other representation of Alternatives