Data.Functor.Polynomial
- Package
- purescript-dissect
- Repository
- PureFunctor/purescript-dissect
Polynomial functors and bifunctors for implementing data types that
comes equipped with free Dissect instances.
#Const Source
#Sum Source
data Sum :: forall k. (k -> Type) -> (k -> Type) -> k -> Typedata Sum a b c
Sum models choice between two polynomial functors.
Sum can also be nested to allow for more variants, although this
comes with the cost of having to unwrap several layers of structure
when performing pattern matching.
Note that the Sum of some type a and Const Void is the same
as just the type a.
0 (Const Void) + a ~ a
a + 0 (Const Void) ~ a
Constructors
Instances
#Product Source
data Product :: forall k. (k -> Type) -> (k -> Type) -> k -> Typedata Product a b c
Product models a pair of polynomial functors.
Product can also be nested to allow for more variants, although
this comes with the cost of having to unwrap several layers of
structure when performing pattern matching. However, one can make
use of the (:*:) operator for better ergonomics.
Note that the Product of some type a and Const Void is Const
Void, while the Product of some type a and Const Unit is
just the type a.
0 (Const Void) * a ~ 0 (Const Void)
a * 0 (Const Void) ~ 0 (Const Void)
1 (Const Unit) * a ~ a
a * 1 (Const Unit) ~ a
Constructors
Product (a c) (b c)
Instances
(Functor a, Functor b) => Functor (Product a b)(Dissect p p', Dissect q q') => Dissect (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))Producteither dissects its left element into a pair of the left element's dissection and an element full of jokers; or it dissects its right element into a pair of the right element's dissection and an element full of clowns.(Plug p p', Plug q q') => Plug (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))
#type (:*:) Source
Operator alias for Data.Functor.Polynomial.Product (right-associative / precedence 4)
#Sum_2 Source
data Sum_2 :: forall k l. (k -> l -> Type) -> (k -> l -> Type) -> k -> l -> Typedata Sum_2 p q a b
Constructors
Instances
(Bifunctor p, Bifunctor q) => Bifunctor (Sum_2 p q)(Dissect p p', Dissect q q') => Dissect (Sum p q) (Sum_2 p' q')Sumdissects both of its polynomial functors.(Dissect p p', Dissect q q') => Dissect (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))Producteither dissects its left element into a pair of the left element's dissection and an element full of jokers; or it dissects its right element into a pair of the right element's dissection and an element full of clowns.(Plug p p', Plug q q') => Plug (Sum p q) (Sum_2 p' q')(Plug p p', Plug q q') => Plug (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))
#Product_2 Source
data Product_2 :: forall k l. (k -> l -> Type) -> (k -> l -> Type) -> k -> l -> Typedata Product_2 p q a b
Constructors
Product_2 (p a b) (q a b)
Instances
(Bifunctor p, Bifunctor q) => Bifunctor (Product_2 p q)(Dissect p p', Dissect q q') => Dissect (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))Producteither dissects its left element into a pair of the left element's dissection and an element full of jokers; or it dissects its right element into a pair of the right element's dissection and an element full of clowns.(Plug p p', Plug q q') => Plug (Product p q) (Sum_2 (Product_2 p' (Joker q)) (Product_2 (Clown p) q'))
Consthas no positions for elements, making it impossible to dissect them further.