distributors
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Traversable.Homogeneous

Description

 
Synopsis

Homogeneous

class Traversable t => Homogeneous (t :: Type -> Type) where Source #

A class of Homogeneous countable sums of countable products.

They shape Diopters, & two subclasses of them shape two kinds of Diopter: countable products, which are Traversable ∩ Distributive, shape Monocles, & countable sums of single copies, which are Enumerable, shape Comonocles,

(Traversable ∩ Distributive) ∪ Enumerable ⊂ Homogeneous,

as Monocle ∪ Comonocle ⊂ Diopter.

Minimal complete definition

Nothing

Methods

homogeneously :: Distributor p => p a b -> p (t a) (t b) Source #

Sequences actions homogeneously.

prop> homogeneously @Maybe = optionalP
prop> homogeneously @[] = manyP

Any Traversable & Distributive countable product can be given a default implementation for the homogeneously method with ditraverse.

prop> homogeneously = ditraverse

And any user-defined homogeneous algebraic datatype has a default instance for Homogeneous, by deriving Generic1.

default homogeneously :: (Generic1 t, Homogeneous (Rep1 t), Distributor p) => p a b -> p (t a) (t b) Source #

Instances

Instances details
Homogeneous Complex Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Complex a) (Complex b) Source #

Homogeneous First Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (First a) (First b) Source #

Homogeneous Last Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Last a) (Last b) Source #

Homogeneous Max Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Max a) (Max b) Source #

Homogeneous Min Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Min a) (Min b) Source #

Homogeneous Seq Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Seq a) (Seq b) Source #

Homogeneous Tree Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Tree a) (Tree b) Source #

Homogeneous NonEmpty Source #

One or more, by deriving Generic1, like someP.

>>> zipWithHomogeneous (+) (1 :| [2]) (3 :| [4 :: Int])
Just (4 :| [6])
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (NonEmpty a) (NonEmpty b) Source #

Homogeneous Identity Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Identity a) (Identity b) Source #

Homogeneous Down Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Down a) (Down b) Source #

Homogeneous Dual Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Dual a) (Dual b) Source #

Homogeneous Product Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Product a) (Product b) Source #

Homogeneous Sum Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Sum a) (Sum b) Source #

Homogeneous Par1 Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Par1 a) (Par1 b) Source #

Homogeneous Vector Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Vector a) (Vector b) Source #

Homogeneous Maybe Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Maybe a) (Maybe b) Source #

Homogeneous [] Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p [a] [b] Source #

Homogeneous (Proxy :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Proxy a) (Proxy b) Source #

Homogeneous (U1 :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (U1 a) (U1 b) Source #

Homogeneous (V1 :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (V1 a) (V1 b) Source #

(Enum e, Bounded e) => Homogeneous ((,) e) Source #

A copy tagged by a finite enumeration is a copy for each tag, summed in a balanceBy tree, built lazily.

>>> zipWithHomogeneous (+) (True, 1) (True, 2 :: Int)
Just (True,3)
>>> zipWithHomogeneous (+) (True, 1) (False, 2 :: Int)
Nothing
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (e, a) (e, b) Source #

Homogeneous (Const Void :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Const Void a) (Const Void b) Source #

Homogeneous (Const () :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Const () a) (Const () b) Source #

Homogeneous f => Homogeneous (Ap f) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Ap f a) (Ap f b) Source #

Homogeneous f => Homogeneous (Alt f) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Alt f a) (Alt f b) Source #

Homogeneous f => Homogeneous (Rec1 f) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Rec1 f a) (Rec1 f b) Source #

Homogeneous (Tagged s) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Tagged s a) (Tagged s b) Source #

Homogeneous f => Homogeneous (IdentityT f) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (IdentityT f a) (IdentityT f b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (Product s t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Product s t a) (Product s t b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (Sum s t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Sum s t a) (Sum s t b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (s :*: t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p ((s :*: t) a) ((s :*: t) b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (s :+: t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p ((s :+: t) a) ((s :+: t) b) Source #

Homogeneous (K1 i Void :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (K1 i Void a) (K1 i Void b) Source #

Homogeneous (K1 i () :: Type -> Type) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (K1 i () a) (K1 i () b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (Compose s t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (Compose s t a) (Compose s t b) Source #

(Homogeneous s, Homogeneous t) => Homogeneous (s :.: t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p ((s :.: t) a) ((s :.: t) b) Source #

Homogeneous t => Homogeneous (M1 i c t) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

homogeneously :: Distributor p => p a b -> p (M1 i c t a) (M1 i c t b) Source #

zipHomogeneous :: (Homogeneous t, Traversable f, Alternative g) => (f a -> g b) -> f (t a) -> g (t b) Source #

Zip Homogeneous structures in the positions of a Traversable, by a function of their elements at each position, when they have the same shape, or else empty.

>>> zipHomogeneous (Just . sum) [[1, 2], [3, 4], [5, 6 :: Int]]
Just [9,12]
>>> zipHomogeneous (Just . sum) [[1, 2], [3 :: Int]]
Nothing
>>> zipHomogeneous id [[1, 2], [3, 4 :: Int]]
[[1,2],[1,4],[3,2],[3,4]]

zipWithHomogeneous :: Homogeneous t => (a -> a -> b) -> t a -> t a -> Maybe (t b) Source #

Zip two Homogeneous structures, when they have the same shape.

>>> zipWithHomogeneous (+) [1, 2] [3, 4 :: Int]
Just [4,6]
>>> zipWithHomogeneous (+) [1] [3, 4 :: Int]
Nothing

zipWithHomogeneous3 :: Homogeneous t => (a -> a -> a -> b) -> t a -> t a -> t a -> Maybe (t b) Source #

Zip three Homogeneous structures, when they have the same shape.

>>> zipWithHomogeneous3 (\a b c -> a + b + c) [1, 2] [3, 4] [5, 6 :: Int]
Just [9,12]
>>> zipWithHomogeneous3 (\a b c -> a + b + c) [1, 2] [3, 4] [5 :: Int]
Nothing

zipWithHomogeneousM :: (Homogeneous t, Applicative m) => (a -> a -> m b) -> t a -> t a -> m (Maybe (t b)) Source #

Zip two Homogeneous structures by an action, when they have the same shape. The actions of the positions which match run, even when the shapes differ elsewhere.

>>> zipWithHomogeneousM (\a b -> ([a + b], a * b)) [1, 2] [3, 4 :: Int]
([4,6],Just [3,8])
>>> zipWithHomogeneousM (\a b -> ([a + b], a * b)) [1, 2] [3 :: Int]
([4],Nothing)

transposeHomogeneous :: (Homogeneous t, Traversable f) => f (t a) -> Maybe (t (f a)) Source #

Transpose Homogeneous structures in the positions of a Traversable, when they have the same shape. Without any structures, a sum's first copy repeats, so that a list is infinite.

>>> transposeHomogeneous [[1, 2, 3], [4, 5, 6 :: Int]]
Just [[1,4],[2,5],[3,6]]
>>> transposeHomogeneous [[1, 2], [3 :: Int]]
Nothing

Zipporah

newtype Zipporah (p :: Type -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type) a b Source #

Zipporah is a profunctor p between functors, like Biff, but lifting p's instances through g, & splitting sums by f, which fail in g unless every position of f holds the same copy.

Constructors

Zipporah 

Fields

Instances

Instances details
(Choice p, Monoidal p, Traversable f, Alternative g) => Alternator (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

someP :: Zipporah p f g a b -> Zipporah p f g [a] [b] Source #

optionP :: APrism a b () () -> Zipporah p f g a b -> Zipporah p f g a b Source #

manyTillP :: Zipporah p f g a b -> Zipporah p f g [a] [b] -> Zipporah p f g [a] [b] Source #

quantP :: Int -> Maybe Int -> Zipporah p f g a b -> Zipporah p f g [a] [b] Source #

(Choice p, Monoidal p, Traversable f, Alternative g) => Distributor (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

optionalP :: Zipporah p f g a b -> Zipporah p f g (Maybe a) (Maybe b) Source #

manyP :: Zipporah p f g a b -> Zipporah p f g [a] [b] Source #

(Choice p, Monoidal p, Traversable f, Alternative g) => CocartesianChoice (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

alternate :: Either (Zipporah p f g a b) (Zipporah p f g c d) -> Zipporah p f g (Either a c) (Either b d) Source #

(Choice p, Monoidal p, Traversable f, Alternative g) => CocartesianMonoidal (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

zeroP :: Zipporah p f g Void Void Source #

(>+<) :: Zipporah p f g a b -> Zipporah p f g c d -> Zipporah p f g (Either a c) (Either b d) Source #

(Choice p, Traversable f, Alternative g) => Choice (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

left' :: Zipporah p f g a b -> Zipporah p f g (Either a c) (Either b c) #

right' :: Zipporah p f g a b -> Zipporah p f g (Either c a) (Either c b) #

(Profunctor p, Functor f, Filterable g) => Cochoice (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

unleft :: Zipporah p f g (Either a d) (Either b d) -> Zipporah p f g a b #

unright :: Zipporah p f g (Either d a) (Either d b) -> Zipporah p f g a b #

(Profunctor p, Functor f, Functor g) => Profunctor (Zipporah p f g) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

dimap :: (a -> b) -> (c -> d) -> Zipporah p f g b c -> Zipporah p f g a d #

lmap :: (a -> b) -> Zipporah p f g b c -> Zipporah p f g a c #

rmap :: (b -> c) -> Zipporah p f g a b -> Zipporah p f g a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Zipporah p f g a b -> Zipporah p f g a c #

(.#) :: forall a b c q. Coercible b a => Zipporah p f g b c -> q a b -> Zipporah p f g a c #

(Monoidal p, Alternative g) => Alternative (Zipporah p f g a) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

empty :: Zipporah p f g a a0 #

(<|>) :: Zipporah p f g a a0 -> Zipporah p f g a a0 -> Zipporah p f g a a0 #

some :: Zipporah p f g a a0 -> Zipporah p f g a [a0] #

many :: Zipporah p f g a a0 -> Zipporah p f g a [a0] #

(Monoidal p, Applicative g) => Applicative (Zipporah p f g a) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

pure :: a0 -> Zipporah p f g a a0 #

(<*>) :: Zipporah p f g a (a0 -> b) -> Zipporah p f g a a0 -> Zipporah p f g a b #

liftA2 :: (a0 -> b -> c) -> Zipporah p f g a a0 -> Zipporah p f g a b -> Zipporah p f g a c #

(*>) :: Zipporah p f g a a0 -> Zipporah p f g a b -> Zipporah p f g a b #

(<*) :: Zipporah p f g a a0 -> Zipporah p f g a b -> Zipporah p f g a a0 #

(Profunctor p, Functor g) => Functor (Zipporah p f g a) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

fmap :: (a0 -> b) -> Zipporah p f g a a0 -> Zipporah p f g a b #

(<$) :: a0 -> Zipporah p f g a b -> Zipporah p f g a a0 #

Monadic p => Monad (Zipporah p f Maybe a) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

(>>=) :: Zipporah p f Maybe a a0 -> (a0 -> Zipporah p f Maybe a b) -> Zipporah p f Maybe a b #

(>>) :: Zipporah p f Maybe a a0 -> Zipporah p f Maybe a b -> Zipporah p f Maybe a b #

return :: a0 -> Zipporah p f Maybe a a0 #

(Profunctor p, Filterable g) => Filterable (Zipporah p f g a) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

mapMaybe :: (a0 -> Maybe b) -> Zipporah p f g a a0 -> Zipporah p f g a b #

catMaybes :: Zipporah p f g a (Maybe a0) -> Zipporah p f g a a0 #

filter :: (a0 -> Bool) -> Zipporah p f g a a0 -> Zipporah p f g a a0 #

drain :: Zipporah p f g a a0 -> Zipporah p f g a b #

(Monoidal p, Alternative g) => DisjunctiveMonoid (Zipporah p f g a b) Source # 
Instance details

Defined in Data.Traversable.Homogeneous

Methods

falseP :: Zipporah p f g a b Source #

(>|<) :: Zipporah p f g a b -> Zipporah p f g a b -> Zipporah p f g a b Source #