| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Traversable.Homogeneous
Contents
Description
Synopsis
- class Traversable t => Homogeneous (t :: Type -> Type) where
- homogeneously :: Distributor p => p a b -> p (t a) (t b)
- zipHomogeneous :: (Homogeneous t, Traversable f, Alternative g) => (f a -> g b) -> f (t a) -> g (t b)
- zipWithHomogeneous :: Homogeneous t => (a -> a -> b) -> t a -> t a -> Maybe (t b)
- zipWithHomogeneous3 :: Homogeneous t => (a -> a -> a -> b) -> t a -> t a -> t a -> Maybe (t b)
- zipWithHomogeneousM :: (Homogeneous t, Applicative m) => (a -> a -> m b) -> t a -> t a -> m (Maybe (t b))
- transposeHomogeneous :: (Homogeneous t, Traversable f) => f (t a) -> Maybe (t (f a))
- newtype Zipporah (p :: Type -> Type -> Type) (f :: Type -> Type) (g :: Type -> Type) a b = Zipporah {
- runZipporah :: p (f a) (g b)
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,
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
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
| |