sop-core-0.5.0.2: True Sums of Products

Safe Haskell | None
Language | Haskell2010

Data.SOP.NS

Contents

- Datatypes
- Constructing sums
- Destructing sums
- Application
- Lifting / mapping
- Dealing with ``All` c`
- Comparison
- Collapsing
- Folding and sequencing
- Catamorphism and anamorphism
- Expanding sums to products
- Transformation of index lists and coercions

Description

n-ary sums (and sums of products)

Synopsis

- data NS (a :: k -> Type) (b :: [k]) where
  - Z :: forall {k} (a :: k -> Type) (x :: k) (xs :: [k]). a x -> NS a (x ': xs)
  - S :: forall {k} (a :: k -> Type) (xs :: [k]) (x :: k). NS a xs -> NS a (x ': xs)
- newtype SOP (f :: k -> Type) (xss :: [[k]]) = SOP (NS (NP f) xss)
- unSOP :: forall {k} (f :: k -> Type) (xss :: [[k]]). SOP f xss -> NS (NP f) xss
- type Injection (f :: k -> Type) (xs :: [k]) = f -.-> (K (NS f xs) :: k -> Type)
- injections :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP (Injection f xs) xs
- shift :: forall {a1} (f :: a1 -> Type) (xs :: [a1]) (a2 :: a1) (x :: a1). Injection f xs a2 -> Injection f (x ': xs) a2
- shiftInjection :: forall {a1} (f :: a1 -> Type) (xs :: [a1]) (a2 :: a1) (x :: a1). Injection f xs a2 -> Injection f (x ': xs) a2
- apInjs_NP :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP f xs -> [NS f xs]
- apInjs'_NP :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP f xs -> NP (K (NS f xs) :: k -> Type) xs
- apInjs_POP :: forall {k} (xss :: [[k]]) (f :: k -> Type). SListI xss => POP f xss -> [SOP f xss]
- apInjs'_POP :: forall {k} (xss :: [[k]]) (f :: k -> Type). SListI xss => POP f xss -> NP (K (SOP f xss) :: [k] -> Type) xss
- unZ :: forall {k} f (x :: k). NS f '[x] -> f x
- index_NS :: forall {k} (f :: k -> Type) (xs :: [k]). NS f xs -> Int
- index_SOP :: forall {k} (f :: k -> Type) (xs :: [[k]]). SOP f xs -> Int
- type Ejection (f :: k -> Type) (xs :: [k]) = (K (NS f xs) :: k -> Type) -.-> (Maybe :.: f)
- ejections :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP (Ejection f xs) xs
- shiftEjection :: forall {a1} (f :: a1 -> Type) (x :: a1) (xs :: [a1]) (a2 :: a1). Ejection f xs a2 -> Ejection f (x ': xs) a2
- ap_NS :: forall {k} (f :: k -> Type) (g :: k -> Type) (xs :: [k]). NP (f -.-> g) xs -> NS f xs -> NS g xs
- ap_SOP :: forall {k} (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). POP (f -.-> g) xss -> SOP f xss -> SOP g xss
- liftA_NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g a) -> NS f xs -> NS g xs
- liftA_SOP :: forall {k} (xss :: [[k]]) f g. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a) -> SOP f xss -> SOP g xss
- liftA2_NS :: forall {k} (xs :: [k]) f g h. SListI xs => (forall (a :: k). f a -> g a -> h a) -> NP f xs -> NS g xs -> NS h xs
- liftA2_SOP :: forall {k} (xss :: [[k]]) f g h. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a -> h a) -> POP f xss -> SOP g xss -> SOP h xss
- cliftA_NS :: forall {k} c (xs :: [k]) proxy f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a) -> NS f xs -> NS g xs
- cliftA_SOP :: forall {k} c (xss :: [[k]]) proxy f g. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a) -> SOP f xss -> SOP g xss
- cliftA2_NS :: forall {k} c (xs :: [k]) proxy f g h. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a -> h a) -> NP f xs -> NS g xs -> NS h xs
- cliftA2_SOP :: forall {k} c (xss :: [[k]]) proxy f g h. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a -> h a) -> POP f xss -> SOP g xss -> SOP h xss
- map_NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g a) -> NS f xs -> NS g xs
- map_SOP :: forall {k} (xss :: [[k]]) f g. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a) -> SOP f xss -> SOP g xss
- cmap_NS :: forall {k} c (xs :: [k]) proxy f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a) -> NS f xs -> NS g xs
- cmap_SOP :: forall {k} c (xss :: [[k]]) proxy f g. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a) -> SOP f xss -> SOP g xss
- cliftA2'_NS :: forall {k} (c :: k -> Constraint) (xss :: [[k]]) proxy f g h. All2 c xss => proxy c -> (forall (xs :: [k]). All c xs => f xs -> g xs -> h xs) -> NP f xss -> NS g xss -> NS h xss
- compare_NS :: forall {k} r f g (xs :: [k]). r -> (forall (x :: k). f x -> g x -> r) -> r -> NS f xs -> NS g xs -> r
- ccompare_NS :: forall {k} c proxy r f g (xs :: [k]). All c xs => proxy c -> r -> (forall (x :: k). c x => f x -> g x -> r) -> r -> NS f xs -> NS g xs -> r
- compare_SOP :: forall {k} r (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). r -> (forall (xs :: [k]). NP f xs -> NP g xs -> r) -> r -> SOP f xss -> SOP g xss -> r
- ccompare_SOP :: forall {k} (c :: k -> Constraint) proxy r (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). All2 c xss => proxy c -> r -> (forall (xs :: [k]). All c xs => NP f xs -> NP g xs -> r) -> r -> SOP f xss -> SOP g xss -> r
- collapse_NS :: forall {k} a (xs :: [k]). NS (K a :: k -> Type) xs -> a
- collapse_SOP :: forall {k} (xss :: [[k]]) a. SListI xss => SOP (K a :: k -> Type) xss -> [a]
- ctraverse__NS :: forall {k} c proxy (xs :: [k]) f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g ()) -> NS f xs -> g ()
- ctraverse__SOP :: forall {k} c proxy (xss :: [[k]]) f g. (All2 c xss, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g ()) -> SOP f xss -> g ()
- traverse__NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g ()) -> NS f xs -> g ()
- traverse__SOP :: forall {k} (xss :: [[k]]) f g. (SListI2 xss, Applicative g) => (forall (a :: k). f a -> g ()) -> SOP f xss -> g ()
- cfoldMap_NS :: forall {k} c proxy f (xs :: [k]) m. All c xs => proxy c -> (forall (a :: k). c a => f a -> m) -> NS f xs -> m
- cfoldMap_SOP :: forall {k} c (xs :: [[k]]) m proxy f. (All2 c xs, Monoid m) => proxy c -> (forall (a :: k). c a => f a -> m) -> SOP f xs -> m
- sequence'_NS :: forall {k} f (g :: k -> Type) (xs :: [k]). Applicative f => NS (f :.: g) xs -> f (NS g xs)
- sequence'_SOP :: forall {k} (xss :: [[k]]) f (g :: k -> Type). (SListI xss, Applicative f) => SOP (f :.: g) xss -> f (SOP g xss)
- sequence_NS :: forall (xs :: [Type]) f. (SListI xs, Applicative f) => NS f xs -> f (NS I xs)
- sequence_SOP :: forall (xss :: [[Type]]) f. (All (SListI :: [Type] -> Constraint) xss, Applicative f) => SOP f xss -> f (SOP I xss)
- ctraverse'_NS :: forall {k} c proxy (xs :: [k]) f f' g. (All c xs, Functor g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> NS f xs -> g (NS f' xs)
- ctraverse'_SOP :: forall {k} c (xss :: [[k]]) g proxy f f'. (All2 c xss, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> SOP f xss -> g (SOP f' xss)
- traverse'_NS :: forall {k} (xs :: [k]) f f' g. (SListI xs, Functor g) => (forall (a :: k). f a -> g (f' a)) -> NS f xs -> g (NS f' xs)
- traverse'_SOP :: forall {k} (xss :: [[k]]) g f f'. (SListI2 xss, Applicative g) => (forall (a :: k). f a -> g (f' a)) -> SOP f xss -> g (SOP f' xss)
- ctraverse_NS :: forall c (xs :: [Type]) g proxy f. (All c xs, Applicative g) => proxy c -> (forall a. c a => f a -> g a) -> NP f xs -> g (NP I xs)
- ctraverse_SOP :: forall c (xs :: [[Type]]) g proxy f. (All2 c xs, Applicative g) => proxy c -> (forall a. c a => f a -> g a) -> POP f xs -> g (POP I xs)
- cata_NS :: forall {k} r f (xs :: [k]). (forall (y :: k) (ys :: [k]). f y -> r (y ': ys)) -> (forall (y :: k) (ys :: [k]). r ys -> r (y ': ys)) -> NS f xs -> r xs
- ccata_NS :: forall {k} c proxy r f (xs :: [k]). All c xs => proxy c -> (forall (y :: k) (ys :: [k]). c y => f y -> r (y ': ys)) -> (forall (y :: k) (ys :: [k]). c y => r ys -> r (y ': ys)) -> NS f xs -> r xs
- ana_NS :: forall {k} s f (xs :: [k]). SListI xs => (forall r. s ('[] :: [k]) -> r) -> (forall (y :: k) (ys :: [k]). s (y ': ys) -> Either (f y) (s ys)) -> s xs -> NS f xs
- cana_NS :: forall {k} c proxy s f (xs :: [k]). All c xs => proxy c -> (forall r. s ('[] :: [k]) -> r) -> (forall (y :: k) (ys :: [k]). c y => s (y ': ys) -> Either (f y) (s ys)) -> s xs -> NS f xs
- expand_NS :: forall {k} f (xs :: [k]). SListI xs => (forall (x :: k). f x) -> NS f xs -> NP f xs
- cexpand_NS :: forall {k} c proxy f (xs :: [k]). All c xs => proxy c -> (forall (x :: k). c x => f x) -> NS f xs -> NP f xs
- expand_SOP :: forall {k} f (xss :: [[k]]). All (SListI :: [k] -> Constraint) xss => (forall (x :: k). f x) -> SOP f xss -> POP f xss
- cexpand_SOP :: forall {k} c proxy f (xss :: [[k]]). All2 c xss => proxy c -> (forall (x :: k). c x => f x) -> SOP f xss -> POP f xss
- trans_NS :: forall {k1} {k2} c (xs :: [k1]) (ys :: [k2]) proxy f g. AllZip c xs ys => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> NS f xs -> NS g ys
- trans_SOP :: forall {k1} {k2} c (xss :: [[k1]]) (yss :: [[k2]]) proxy f g. AllZip2 c xss yss => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> SOP f xss -> SOP g yss
- coerce_NS :: forall {k1} {k2} (f :: k1 -> Type) (g :: k2 -> Type) (xs :: [k1]) (ys :: [k2]). AllZip (LiftedCoercible f g) xs ys => NS f xs -> NS g ys
- coerce_SOP :: forall {k1} {k2} (f :: k1 -> Type) (g :: k2 -> Type) (xss :: [[k1]]) (yss :: [[k2]]). AllZip2 (LiftedCoercible f g) xss yss => SOP f xss -> SOP g yss
- fromI_NS :: forall {k} (f :: k -> Type) (xs :: [Type]) (ys :: [k]). AllZip (LiftedCoercible I f) xs ys => NS I xs -> NS f ys
- fromI_SOP :: forall {k} (f :: k -> Type) (xss :: [[Type]]) (yss :: [[k]]). AllZip2 (LiftedCoercible I f) xss yss => SOP I xss -> SOP f yss
- toI_NS :: forall {k} (f :: k -> Type) (xs :: [k]) (ys :: [Type]). AllZip (LiftedCoercible f I) xs ys => NS f xs -> NS I ys
- toI_SOP :: forall {k} (f :: k -> Type) (xss :: [[k]]) (yss :: [[Type]]). AllZip2 (LiftedCoercible f I) xss yss => SOP f xss -> SOP I yss

# Datatypes

data NS (a :: k -> Type) (b :: [k]) where #

An n-ary sum.

The sum is parameterized by a type constructor `f` and indexed by a type-level list `xs`. The length of the list determines the number of choices in the sum and if the `i`-th element of the list is of type `x`, then the `i`-th choice of the sum is of type `f x`.

The constructor names are chosen to resemble Peano-style natural numbers, i.e., `Z` is for "zero", and `S` is for "successor". Chaining `S` and `Z` chooses the corresponding component of the sum.

Examples:

    Z         :: f x -> NS f (x ': xs)
    S . Z     :: f y -> NS f (x ': y ': xs)
    S . S . Z :: f z -> NS f (x ': y ': z ': xs)
    ...

Note that empty sums (indexed by an empty list) have no non-bottom elements.

Two common instantiations of `f` are the identity functor `I` and the constant functor `K`. For `I`, the sum becomes a direct generalization of the `Either` type to arbitrarily many choices. For ``K` a`, the result is a homogeneous choice type, where the contents of the type-level list are ignored, but its length specifies the number of options.

In the context of the SOP approach to generic programming, an n-ary sum describes the top-level structure of a datatype, which is a choice between all of its constructors.

Examples:

    Z (I 'x')      :: NS I       '[ Char, Bool ]
    S (Z (I True)) :: NS I       '[ Char, Bool ]
    S (Z (K 1))    :: NS (K Int) '[ Char, Bool ]

Constructors

Z :: forall {k} (a :: k -> Type) (x :: k) (xs :: [k]). a x -> NS a (x ': xs) |
S :: forall {k} (a :: k -> Type) (xs :: [k]) (x :: k). NS a xs -> NS a (x ': xs) |

#### Instances

Instances details

HTrans (NS :: (k1 -> Type) -> [k1] -> Type) (NS :: (k2 -> Type) -> [k2] -> Type) # |
Instance details Defined in Data.SOP.NS Methods htrans :: forall c (xs :: [k1]) (ys :: [k2]) proxy f g. AllZipN (Prod (NS :: (k1 -> Type) -> [k1] -> Type)) c xs ys => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> NS f xs -> NS g ys # hcoerce :: forall (f :: k1 -> Type) (g :: k2 -> Type) (xs :: [k1]) (ys :: [k2]). AllZipN (Prod (NS :: (k1 -> Type) -> [k1] -> Type)) (LiftedCoercible f g) xs ys => NS f xs -> NS g ys #
HAp (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hap :: forall (f :: k -> Type) (g :: k -> Type) (xs :: [k]). Prod (NS :: (k -> Type) -> [k] -> Type) (f -.-> g) xs -> NS f xs -> NS g xs #
HApInjs (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hapInjs :: forall (xs :: [k]) (f :: k -> Type). SListIN (NS :: (k -> Type) -> [k] -> Type) xs => Prod (NS :: (k -> Type) -> [k] -> Type) f xs -> [NS f xs] #
HCollapse (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hcollapse :: forall (xs :: [k]) a. SListIN (NS :: (k -> Type) -> [k] -> Type) xs => NS (K a :: k -> Type) xs -> CollapseTo (NS :: (k -> Type) -> [k] -> Type) a #
HExpand (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hexpand :: forall (xs :: [k]) f. SListIN (Prod (NS :: (k -> Type) -> [k] -> Type)) xs => (forall (x :: k). f x) -> NS f xs -> Prod (NS :: (k -> Type) -> [k] -> Type) f xs # hcexpand :: forall c (xs :: [k]) proxy f. AllN (Prod (NS :: (k -> Type) -> [k] -> Type)) c xs => proxy c -> (forall (x :: k). c x => f x) -> NS f xs -> Prod (NS :: (k -> Type) -> [k] -> Type) f xs #
HIndex (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hindex :: forall (f :: k -> Type) (xs :: [k]). NS f xs -> Int #
HSequence (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hsequence' :: forall (xs :: [k]) f (g :: k -> Type). (SListIN (NS :: (k -> Type) -> [k] -> Type) xs, Applicative f) => NS (f :.: g) xs -> f (NS g xs) # hctraverse' :: forall c (xs :: [k]) g proxy f f'. (AllN (NS :: (k -> Type) -> [k] -> Type) c xs, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> NS f xs -> g (NS f' xs) # htraverse' :: forall (xs :: [k]) g f f'. (SListIN (NS :: (k -> Type) -> [k] -> Type) xs, Applicative g) => (forall (a :: k). f a -> g (f' a)) -> NS f xs -> g (NS f' xs) #
HTraverse_ (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hctraverse_ :: forall c (xs :: [k]) g proxy f. (AllN (NS :: (k -> Type) -> [k] -> Type) c xs, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g ()) -> NS f xs -> g () # htraverse_ :: forall (xs :: [k]) g f. (SListIN (NS :: (k -> Type) -> [k] -> Type) xs, Applicative g) => (forall (a :: k). f a -> g ()) -> NS f xs -> g () #
All (Compose NFData f) xs => NFData (NS f xs) # | Since: 0.2.5.0
Instance details Defined in Data.SOP.NS Methods rnf :: NS f xs -> () #
All (Compose Show f) xs => Show (NS f xs) # |
Instance details Defined in Data.SOP.NS Methods showsPrec :: Int -> NS f xs -> ShowS # show :: NS f xs -> String # showList :: [NS f xs] -> ShowS #
All (Compose Eq f) xs => Eq (NS f xs) # |
Instance details Defined in Data.SOP.NS Methods (==) :: NS f xs -> NS f xs -> Bool # (/=) :: NS f xs -> NS f xs -> Bool #
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NS f xs) # |
Instance details Defined in Data.SOP.NS Methods compare :: NS f xs -> NS f xs -> Ordering # (<) :: NS f xs -> NS f xs -> Bool # (<=) :: NS f xs -> NS f xs -> Bool # (>) :: NS f xs -> NS f xs -> Bool # (>=) :: NS f xs -> NS f xs -> Bool # max :: NS f xs -> NS f xs -> NS f xs # min :: NS f xs -> NS f xs -> NS f xs #
type Same (NS :: (k1 -> Type) -> [k1] -> Type) # |
Instance details Defined in Data.SOP.NS type Same (NS :: (k1 -> Type) -> [k1] -> Type) = NS :: (k2 -> Type) -> [k2] -> Type
type Prod (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS type Prod (NS :: (k -> Type) -> [k] -> Type) = NP :: (k -> Type) -> [k] -> Type
type SListIN (NS :: (k -> Type) -> [k] -> Type) # |
Instance details Defined in Data.SOP.NS type SListIN (NS :: (k -> Type) -> [k] -> Type) = SListI :: [k] -> Constraint
type CollapseTo (NS :: (k -> Type) -> [k] -> Type) a # |
Instance details Defined in Data.SOP.NS type CollapseTo (NS :: (k -> Type) -> [k] -> Type) a = a
type AllN (NS :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) # |
Instance details Defined in Data.SOP.NS type AllN (NS :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) = All c

newtype SOP (f :: k -> Type) (xss :: [[k]]) #

A sum of products.

This is a 'newtype' for an `NS` of an `NP`. The elements of the (inner) products are applications of the parameter `f`. The type `SOP` is indexed by the list of lists that determines the sizes of both the (outer) sum and all the (inner) products, as well as the types of all the elements of the inner products.

A ``SOP` `I`` reflects the structure of a normal Haskell datatype. The sum structure represents the choice between the different constructors, the product structure represents the arguments of each constructor.

Constructors

SOP (NS (NP f) xss) |

#### Instances

Instances details

HTrans (SOP :: (k1 -> Type) -> [[k1]] -> Type) (SOP :: (k2 -> Type) -> [[k2]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods htrans :: forall c (xs :: [[k1]]) (ys :: [[k2]]) proxy f g. AllZipN (Prod (SOP :: (k1 -> Type) -> [[k1]] -> Type)) c xs ys => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> SOP f xs -> SOP g ys # hcoerce :: forall (f :: k1 -> Type) (g :: k2 -> Type) (xs :: [[k1]]) (ys :: [[k2]]). AllZipN (Prod (SOP :: (k1 -> Type) -> [[k1]] -> Type)) (LiftedCoercible f g) xs ys => SOP f xs -> SOP g ys #
HAp (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hap :: forall (f :: k -> Type) (g :: k -> Type) (xs :: [[k]]). Prod (SOP :: (k -> Type) -> [[k]] -> Type) (f -.-> g) xs -> SOP f xs -> SOP g xs #
HApInjs (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hapInjs :: forall (xs :: [[k]]) (f :: k -> Type). SListIN (SOP :: (k -> Type) -> [[k]] -> Type) xs => Prod (SOP :: (k -> Type) -> [[k]] -> Type) f xs -> [SOP f xs] #
HCollapse (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hcollapse :: forall (xs :: [[k]]) a. SListIN (SOP :: (k -> Type) -> [[k]] -> Type) xs => SOP (K a :: k -> Type) xs -> CollapseTo (SOP :: (k -> Type) -> [[k]] -> Type) a #
HExpand (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hexpand :: forall (xs :: [[k]]) f. SListIN (Prod (SOP :: (k -> Type) -> [[k]] -> Type)) xs => (forall (x :: k). f x) -> SOP f xs -> Prod (SOP :: (k -> Type) -> [[k]] -> Type) f xs # hcexpand :: forall c (xs :: [[k]]) proxy f. AllN (Prod (SOP :: (k -> Type) -> [[k]] -> Type)) c xs => proxy c -> (forall (x :: k). c x => f x) -> SOP f xs -> Prod (SOP :: (k -> Type) -> [[k]] -> Type) f xs #
HIndex (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hindex :: forall (f :: k -> Type) (xs :: [[k]]). SOP f xs -> Int #
HSequence (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hsequence' :: forall (xs :: [[k]]) f (g :: k -> Type). (SListIN (SOP :: (k -> Type) -> [[k]] -> Type) xs, Applicative f) => SOP (f :.: g) xs -> f (SOP g xs) # hctraverse' :: forall c (xs :: [[k]]) g proxy f f'. (AllN (SOP :: (k -> Type) -> [[k]] -> Type) c xs, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> SOP f xs -> g (SOP f' xs) # htraverse' :: forall (xs :: [[k]]) g f f'. (SListIN (SOP :: (k -> Type) -> [[k]] -> Type) xs, Applicative g) => (forall (a :: k). f a -> g (f' a)) -> SOP f xs -> g (SOP f' xs) #
HTraverse_ (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS Methods hctraverse_ :: forall c (xs :: [[k]]) g proxy f. (AllN (SOP :: (k -> Type) -> [[k]] -> Type) c xs, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g ()) -> SOP f xs -> g () # htraverse_ :: forall (xs :: [[k]]) g f. (SListIN (SOP :: (k -> Type) -> [[k]] -> Type) xs, Applicative g) => (forall (a :: k). f a -> g ()) -> SOP f xs -> g () #
NFData (NS (NP f) xss) => NFData (SOP f xss) # | Since: 0.2.5.0
Instance details Defined in Data.SOP.NS Methods rnf :: SOP f xss -> () #
Show (NS (NP f) xss) => Show (SOP f xss) # |
Instance details Defined in Data.SOP.NS Methods showsPrec :: Int -> SOP f xss -> ShowS # show :: SOP f xss -> String # showList :: [SOP f xss] -> ShowS #
Eq (NS (NP f) xss) => Eq (SOP f xss) # |
Instance details Defined in Data.SOP.NS Methods (==) :: SOP f xss -> SOP f xss -> Bool # (/=) :: SOP f xss -> SOP f xss -> Bool #
Ord (NS (NP f) xss) => Ord (SOP f xss) # |
Instance details Defined in Data.SOP.NS Methods compare :: SOP f xss -> SOP f xss -> Ordering # (<) :: SOP f xss -> SOP f xss -> Bool # (<=) :: SOP f xss -> SOP f xss -> Bool # (>) :: SOP f xss -> SOP f xss -> Bool # (>=) :: SOP f xss -> SOP f xss -> Bool # max :: SOP f xss -> SOP f xss -> SOP f xss # min :: SOP f xss -> SOP f xss -> SOP f xss #
type Same (SOP :: (k1 -> Type) -> [[k1]] -> Type) # |
Instance details Defined in Data.SOP.NS type Same (SOP :: (k1 -> Type) -> [[k1]] -> Type) = SOP :: (k2 -> Type) -> [[k2]] -> Type
type Prod (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS type Prod (SOP :: (k -> Type) -> [[k]] -> Type) = POP :: (k -> Type) -> [[k]] -> Type
type SListIN (SOP :: (k -> Type) -> [[k]] -> Type) # |
Instance details Defined in Data.SOP.NS type SListIN (SOP :: (k -> Type) -> [[k]] -> Type) = SListI2 :: [[k]] -> Constraint
type CollapseTo (SOP :: (k -> Type) -> [[k]] -> Type) a # |
Instance details Defined in Data.SOP.NS type CollapseTo (SOP :: (k -> Type) -> [[k]] -> Type) a = [a]
type AllN (SOP :: (k -> Type) -> [[k]] -> Type) (c :: k -> Constraint) # |
Instance details Defined in Data.SOP.NS type AllN (SOP :: (k -> Type) -> [[k]] -> Type) (c :: k -> Constraint) = All2 c

unSOP :: forall {k} (f :: k -> Type) (xss :: [[k]]). SOP f xss -> NS (NP f) xss #

Unwrap a sum of products.

# Constructing sums

type Injection (f :: k -> Type) (xs :: [k]) = f -.-> (K (NS f xs) :: k -> Type) #

The type of injections into an n-ary sum.

If you expand the type synonyms and newtypes involved, you get

    Injection f xs a = (f -.-> K (NS f xs)) a ~= f a -> K (NS f xs) a ~= f a -> NS f xs

If we pick `a` to be an element of `xs`, this indeed corresponds to an injection into the sum.

injections :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP (Injection f xs) xs #

Compute all injections into an n-ary sum.

Each element of the resulting product contains one of the injections.

shift :: forall {a1} (f :: a1 -> Type) (xs :: [a1]) (a2 :: a1) (x :: a1). Injection f xs a2 -> Injection f (x ': xs) a2 #

Deprecated: Use `shiftInjection` instead.

Shift an injection.

Given an injection, return an injection into a sum that is one component larger.

shiftInjection :: forall {a1} (f :: a1 -> Type) (xs :: [a1]) (a2 :: a1) (x :: a1). Injection f xs a2 -> Injection f (x ': xs) a2 #

Shift an injection.

Given an injection, return an injection into a sum that is one component larger.

apInjs_NP :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP f xs -> [NS f xs] #

Apply injections to a product.

Given a product containing all possible choices, produce a list of sums by applying each injection to the appropriate element.

Example:

    >>> apInjs_NP (I 'x' :* I True :* I 2 :* Nil)
    [Z (I 'x'),S (Z (I True)),S (S (Z (I 2)))]

apInjs'_NP :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP f xs -> NP (K (NS f xs) :: k -> Type) xs #

`apInjs_NP` without `hcollapse`.

    >>> apInjs'_NP (I 'x' :* I True :* I 2 :* Nil)
    K (Z (I 'x')) :* K (S (Z (I True))) :* K (S (S (Z (I 2)))) :* Nil

Since: 0.2.5.0

apInjs_POP :: forall {k} (xss :: [[k]]) (f :: k -> Type). SListI xss => POP f xss -> [SOP f xss] #

Apply injections to a product of product.

This operates on the outer product only. Given a product containing all possible choices (that are products), produce a list of sums (of products) by applying each injection to the appropriate element.

Example:

    >>> apInjs_POP (POP ((I 'x' :* Nil) :* (I True :* I 2 :* Nil) :* Nil))
    [SOP (Z (I 'x' :* Nil)),SOP (S (Z (I True :* I 2 :* Nil)))]

apInjs'_POP :: forall {k} (xss :: [[k]]) (f :: k -> Type). SListI xss => POP f xss -> NP (K (SOP f xss) :: [k] -> Type) xss #

`apInjs_POP` without `hcollapse`.

Example:

    >>> apInjs'_POP (POP ((I 'x' :* Nil) :* (I True :* I 2 :* Nil) :* Nil))
    K (SOP (Z (I 'x' :* Nil))) :* K (SOP (S (Z (I True :* I 2 :* Nil)))) :* Nil

Since: 0.2.5.0

# Destructing sums

unZ :: forall {k} f (x :: k). NS f '[x] -> f x #

Extract the payload from a unary sum.

For larger sums, this function would be partial, so it is only provided with a rather restrictive type.

Example:

    >>> unZ (Z (I 'x'))
    I 'x'

Since: 0.2.2.0

index_NS :: forall {k} (f :: k -> Type) (xs :: [k]). NS f xs -> Int #

Obtain the index from an n-ary sum.

An n-nary sum represents a choice between n different options. This function returns an integer between 0 and n - 1 indicating the option chosen by the given value.

Examples:

    >>> index_NS (S (S (Z (I False))))
    2
    >>> index_NS (Z (K ()))
    0

Since: 0.2.4.0

index_SOP :: forall {k} (f :: k -> Type) (xs :: [[k]]). SOP f xs -> Int #

Obtain the index from an n-ary sum of products.

An n-nary sum represents a choice between n different options. This function returns an integer between 0 and n - 1 indicating the option chosen by the given value.

Specification:

    index_SOP = index_NS . unSOP

Example:

    >>> index_SOP (SOP (S (Z (I True :* I 'x' :* Nil))))
    1

Since: 0.2.4.0

type Ejection (f :: k -> Type) (xs :: [k]) = (K (NS f xs) :: k -> Type) -.-> (Maybe :.: f) #

The type of ejections from an n-ary sum.

An ejection is the pattern matching function for one part of the n-ary sum.

It is the opposite of an `Injection`.

Since: 0.5.0.0

ejections :: forall {k} (xs :: [k]) (f :: k -> Type). SListI xs => NP (Ejection f xs) xs #

Compute all ejections from an n-ary sum.

Each element of the resulting product contains one of the ejections.

Since: 0.5.0.0

shiftEjection :: forall {a1} (f :: a1 -> Type) (x :: a1) (xs :: [a1]) (a2 :: a1). Ejection f xs a2 -> Ejection f (x ': xs) a2 #

Since: 0.5.0.0

# Application

ap_NS :: forall {k} (f :: k -> Type) (g :: k -> Type) (xs :: [k]). NP (f -.-> g) xs -> NS f xs -> NS g xs #

Specialization of `hap`.

ap_SOP :: forall {k} (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). POP (f -.-> g) xss -> SOP f xss -> SOP g xss #

Specialization of `hap`.

# Lifting / mapping

liftA_NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g a) -> NS f xs -> NS g xs #

Specialization of `hliftA`.

liftA_SOP :: forall {k} (xss :: [[k]]) f g. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a) -> SOP f xss -> SOP g xss #

Specialization of `hliftA`.

liftA2_NS :: forall {k} (xs :: [k]) f g h. SListI xs => (forall (a :: k). f a -> g a -> h a) -> NP f xs -> NS g xs -> NS h xs #

Specialization of `hliftA2`.

liftA2_SOP :: forall {k} (xss :: [[k]]) f g h. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a -> h a) -> POP f xss -> SOP g xss -> SOP h xss #

Specialization of `hliftA2`.

cliftA_NS :: forall {k} c (xs :: [k]) proxy f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a) -> NS f xs -> NS g xs #

Specialization of `hcliftA`.

cliftA_SOP :: forall {k} c (xss :: [[k]]) proxy f g. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a) -> SOP f xss -> SOP g xss #

Specialization of `hcliftA`.

cliftA2_NS :: forall {k} c (xs :: [k]) proxy f g h. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a -> h a) -> NP f xs -> NS g xs -> NS h xs #

Specialization of `hcliftA2`.

cliftA2_SOP :: forall {k} c (xss :: [[k]]) proxy f g h. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a -> h a) -> POP f xss -> SOP g xss -> SOP h xss #

Specialization of `hcliftA2`.

map_NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g a) -> NS f xs -> NS g xs #

Specialization of `hmap`, which is equivalent to `hliftA`.

map_SOP :: forall {k} (xss :: [[k]]) f g. All (SListI :: [k] -> Constraint) xss => (forall (a :: k). f a -> g a) -> SOP f xss -> SOP g xss #

Specialization of `hmap`, which is equivalent to `hliftA`.

cmap_NS :: forall {k} c (xs :: [k]) proxy f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g a) -> NS f xs -> NS g xs #

Specialization of `hcmap`, which is equivalent to `hcliftA`.

cmap_SOP :: forall {k} c (xss :: [[k]]) proxy f g. All2 c xss => proxy c -> (forall (a :: k). c a => f a -> g a) -> SOP f xss -> SOP g xss #

Specialization of `hcmap`, which is equivalent to `hcliftA`.

# Dealing with ``All` c`

cliftA2'_NS :: forall {k} (c :: k -> Constraint) (xss :: [[k]]) proxy f g h. All2 c xss => proxy c -> (forall (xs :: [k]). All c xs => f xs -> g xs -> h xs) -> NP f xss -> NS g xss -> NS h xss #

Deprecated: Use `cliftA2_NS` instead.

Specialization of `hcliftA2'`.

# Comparison

compare_NS #

Arguments

:: forall {k} r f g (xs :: [k]). r | what to do if first is smaller
-> (forall (x :: k). f x -> g x -> r) | what to do if both are equal
-> r | what to do if first is larger
-> NS f xs |
-> NS g xs |
-> r |

Compare two sums with respect to the choice they are making.

A value that chooses the first option is considered smaller than one that chooses the second option.

If the choices are different, then either the first (if the first is smaller than the second) or the third (if the first is larger than the second) argument are called. If both choices are equal, then the second argument is called, which has access to the elements contained in the sums.

Since: 0.3.2.0

ccompare_NS #

Arguments

:: forall {k} c proxy r f g (xs :: [k]). All c xs |
=> proxy c |
-> r | what to do if first is smaller
-> (forall (x :: k). c x => f x -> g x -> r) | what to do if both are equal
-> r | what to do if first is larger
-> NS f xs |
-> NS g xs |
-> r |

Constrained version of `compare_NS`.

Since: 0.3.2.0

compare_SOP #

Arguments

:: forall {k} r (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). r | what to do if first is smaller
-> (forall (xs :: [k]). NP f xs -> NP g xs -> r) | what to do if both are equal
-> r | what to do if first is larger
-> SOP f xss |
-> SOP g xss |
-> r |

Compare two sums of products with respect to the choice in the sum they are making.

Only the sum structure is used for comparison. This is a small wrapper around `ccompare_NS` for a common special case.

Since: 0.3.2.0

ccompare_SOP #

Arguments

:: forall {k} (c :: k -> Constraint) proxy r (f :: k -> Type) (g :: k -> Type) (xss :: [[k]]). All2 c xss |
=> proxy c |
-> r | what to do if first is smaller
-> (forall (xs :: [k]). All c xs => NP f xs -> NP g xs -> r) | what to do if both are equal
-> r | what to do if first is larger
-> SOP f xss |
-> SOP g xss |
-> r |

Constrained version of `compare_SOP`.

Since: 0.3.2.0

# Collapsing

collapse_NS :: forall {k} a (xs :: [k]). NS (K a :: k -> Type) xs -> a #

Specialization of `hcollapse`.

collapse_SOP :: forall {k} (xss :: [[k]]) a. SListI xss => SOP (K a :: k -> Type) xss -> [a] #

Specialization of `hcollapse`.

# Folding and sequencing

ctraverse__NS :: forall {k} c proxy (xs :: [k]) f g. All c xs => proxy c -> (forall (a :: k). c a => f a -> g ()) -> NS f xs -> g () #

Specialization of `hctraverse_`.

Note: we don't need `Applicative` constraint.

Since: 0.3.2.0

ctraverse__SOP :: forall {k} c proxy (xss :: [[k]]) f g. (All2 c xss, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g ()) -> SOP f xss -> g () #

Specialization of `hctraverse_`.

Since: 0.3.2.0

traverse__NS :: forall {k} (xs :: [k]) f g. SListI xs => (forall (a :: k). f a -> g ()) -> NS f xs -> g () #

Specialization of `htraverse_`.

Note: we don't need `Applicative` constraint.

Since: 0.3.2.0

traverse__SOP :: forall {k} (xss :: [[k]]) f g. (SListI2 xss, Applicative g) => (forall (a :: k). f a -> g ()) -> SOP f xss -> g () #

Specialization of `htraverse_`.

Since: 0.3.2.0

cfoldMap_NS :: forall {k} c proxy f (xs :: [k]) m. All c xs => proxy c -> (forall (a :: k). c a => f a -> m) -> NS f xs -> m #

Specialization of `hcfoldMap`.

Note: We don't need `Monoid` instance.

Since: 0.3.2.0

cfoldMap_SOP :: forall {k} c (xs :: [[k]]) m proxy f. (All2 c xs, Monoid m) => proxy c -> (forall (a :: k). c a => f a -> m) -> SOP f xs -> m #

Specialization of `hcfoldMap`.

Since: 0.3.2.0

sequence'_NS :: forall {k} f (g :: k -> Type) (xs :: [k]). Applicative f => NS (f :.: g) xs -> f (NS g xs) #

Specialization of `hsequence'`.

sequence'_SOP :: forall {k} (xss :: [[k]]) f (g :: k -> Type). (SListI xss, Applicative f) => SOP (f :.: g) xss -> f (SOP g xss) #

Specialization of `hsequence'`.

sequence_NS :: forall (xs :: [Type]) f. (SListI xs, Applicative f) => NS f xs -> f (NS I xs) #

Specialization of `hsequence`.

sequence_SOP :: forall (xss :: [[Type]]) f. (All (SListI :: [Type] -> Constraint) xss, Applicative f) => SOP f xss -> f (SOP I xss) #

Specialization of `hsequence`.

ctraverse'_NS :: forall {k} c proxy (xs :: [k]) f f' g. (All c xs, Functor g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> NS f xs -> g (NS f' xs) #

Specialization of `hctraverse'`.

Note: as `NS` has exactly one element, the `Functor` constraint is enough.

Since: 0.3.2.0

ctraverse'_SOP :: forall {k} c (xss :: [[k]]) g proxy f f'. (All2 c xss, Applicative g) => proxy c -> (forall (a :: k). c a => f a -> g (f' a)) -> SOP f xss -> g (SOP f' xss) #

Specialization of `hctraverse'`.

Since: 0.3.2.0

traverse'_NS :: forall {k} (xs :: [k]) f f' g. (SListI xs, Functor g) => (forall (a :: k). f a -> g (f' a)) -> NS f xs -> g (NS f' xs) #

Specialization of `htraverse'`.

Note: as `NS` has exactly one element, the `Functor` constraint is enough.

Since: 0.3.2.0

traverse'_SOP :: forall {k} (xss :: [[k]]) g f f'. (SListI2 xss, Applicative g) => (forall (a :: k). f a -> g (f' a)) -> SOP f xss -> g (SOP f' xss) #

Specialization of `htraverse'`.

Since: 0.3.2.0

ctraverse_NS :: forall c (xs :: [Type]) g proxy f. (All c xs, Applicative g) => proxy c -> (forall a. c a => f a -> g a) -> NP f xs -> g (NP I xs) #

Specialization of `hctraverse`.

Since: 0.3.2.0

ctraverse_SOP :: forall c (xs :: [[Type]]) g proxy f. (All2 c xs, Applicative g) => proxy c -> (forall a. c a => f a -> g a) -> POP f xs -> g (POP I xs) #

Specialization of `hctraverse`.

Since: 0.3.2.0

# Catamorphism and anamorphism

cata_NS :: forall {k} r f (xs :: [k]). (forall (y :: k) (ys :: [k]). f y -> r (y ': ys)) -> (forall (y :: k) (ys :: [k]). r ys -> r (y ': ys)) -> NS f xs -> r xs #

Catamorphism for `NS`.

Takes arguments determining what to do for `Z` and what to do for `S`. The result type is still indexed over the type-level lit.

Since: 0.2.3.0

ccata_NS :: forall {k} c proxy r f (xs :: [k]). All c xs => proxy c -> (forall (y :: k) (ys :: [k]). c y => f y -> r (y ': ys)) -> (forall (y :: k) (ys :: [k]). c y => r ys -> r (y ': ys)) -> NS f xs -> r xs #

Constrained catamorphism for `NS`.

Since: 0.2.3.0

ana_NS :: forall {k} s f (xs :: [k]). SListI xs => (forall r. s ('[] :: [k]) -> r) -> (forall (y :: k) (ys :: [k]). s (y ': ys) -> Either (f y) (s ys)) -> s xs -> NS f xs #

Anamorphism for `NS`.

Since: 0.2.3.0

cana_NS :: forall {k} c proxy s f (xs :: [k]). All c xs => proxy c -> (forall r. s ('[] :: [k]) -> r) -> (forall (y :: k) (ys :: [k]). c y => s (y ': ys) -> Either (f y) (s ys)) -> s xs -> NS f xs #

Constrained anamorphism for `NS`.

Since: 0.2.3.0

# Expanding sums to products

expand_NS :: forall {k} f (xs :: [k]). SListI xs => (forall (x :: k). f x) -> NS f xs -> NP f xs #

Specialization of `hexpand`.

Since: 0.2.5.0

cexpand_NS :: forall {k} c proxy f (xs :: [k]). All c xs => proxy c -> (forall (x :: k). c x => f x) -> NS f xs -> NP f xs #

Specialization of `hcexpand`.

Since: 0.2.5.0

expand_SOP :: forall {k} f (xss :: [[k]]). All (SListI :: [k] -> Constraint) xss => (forall (x :: k). f x) -> SOP f xss -> POP f xss #

Specialization of `hexpand`.

Since: 0.2.5.0

cexpand_SOP :: forall {k} c proxy f (xss :: [[k]]). All2 c xss => proxy c -> (forall (x :: k). c x => f x) -> SOP f xss -> POP f xss #

Specialization of `hcexpand`.

Since: 0.2.5.0

# Transformation of index lists and coercions

trans_NS :: forall {k1} {k2} c (xs :: [k1]) (ys :: [k2]) proxy f g. AllZip c xs ys => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> NS f xs -> NS g ys #

Specialization of `htrans`.

Since: 0.3.1.0

trans_SOP :: forall {k1} {k2} c (xss :: [[k1]]) (yss :: [[k2]]) proxy f g. AllZip2 c xss yss => proxy c -> (forall (x :: k1) (y :: k2). c x y => f x -> g y) -> SOP f xss -> SOP g yss #

Specialization of `htrans`.

Since: 0.3.1.0

coerce_NS :: forall {k1} {k2} (f :: k1 -> Type) (g :: k2 -> Type) (xs :: [k1]) (ys :: [k2]). AllZip (LiftedCoercible f g) xs ys => NS f xs -> NS g ys #

Specialization of `hcoerce`.

Since: 0.3.1.0

coerce_SOP :: forall {k1} {k2} (f :: k1 -> Type) (g :: k2 -> Type) (xss :: [[k1]]) (yss :: [[k2]]). AllZip2 (LiftedCoercible f g) xss yss => SOP f xss -> SOP g yss #

Specialization of `hcoerce`.

Since: 0.3.1.0

fromI_NS :: forall {k} (f :: k -> Type) (xs :: [Type]) (ys :: [k]). AllZip (LiftedCoercible I f) xs ys => NS I xs -> NS f ys #

Specialization of `hfromI`.

Since: 0.3.1.0

fromI_SOP :: forall {k} (f :: k -> Type) (xss :: [[Type]]) (yss :: [[k]]). AllZip2 (LiftedCoercible I f) xss yss => SOP I xss -> SOP f yss #

Specialization of `hfromI`.

Since: 0.3.1.0

toI_NS :: forall {k} (f :: k -> Type) (xs :: [k]) (ys :: [Type]). AllZip (LiftedCoercible f I) xs ys => NS f xs -> NS I ys #

Specialization of `htoI`.

Since: 0.3.1.0

toI_SOP :: forall {k} (f :: k -> Type) (xss :: [[k]]) (yss :: [[Type]]). AllZip2 (LiftedCoercible f I) xss yss => SOP f xss -> SOP I yss #

Specialization of `htoI`.

Since: 0.3.1.0