-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Align and Zip type-classes from the common Semialign ancestor. -- -- The major use of These of this is provided by the -- align member of Semialign class, representing a -- generalized notion of "zipping with padding" that combines structures -- without truncating to the size of the smaller input. -- -- It turns out that zip operation fits well the -- Semialign class, forming lattice-like structure. @package semialign @version 1.3 -- | Zipping and aligning of indexed functors. module Data.Semialign.Indexed -- | Indexed version of Semialign. class (FunctorWithIndex i f, Semialign f) => SemialignWithIndex i f | f -> i -- | Analogous to alignWith, but also provides an index. ialignWith :: SemialignWithIndex i f => (i -> These a b -> c) -> f a -> f b -> f c -- | Indexed version of Zip. class (SemialignWithIndex i f, Zip f) => ZipWithIndex i f | f -> i -- | Analogous to zipWith, but also provides an index. izipWith :: ZipWithIndex i f => (i -> a -> b -> c) -> f a -> f b -> f c -- | Indexed version of Repeat. class (ZipWithIndex i f, Repeat f) => RepeatWithIndex i f | f -> i -- | Analogous to repeat, but also provides an index. -- -- This should be the same as tabulate for representable -- functors. irepeat :: RepeatWithIndex i f => (i -> a) -> f a -- | Zipping and aligning of functors with non-uniform shapes. module Data.Semialign -- | Functors supporting an align operation that takes the union of -- non-uniform shapes. -- -- Minimal definition: either align or alignWith. -- --
-- join align ≡ fmap (join These) ---- -- Commutativity -- --
-- align x y ≡ swap <$> align y x ---- -- Associativity -- --
-- align x (align y z) ≡ assoc <$> align (align x y) z ---- -- With -- --
-- alignWith f a b ≡ f <$> align a b ---- -- Functoriality -- --
-- align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y ---- -- Alignedness, if f is Foldable -- --
-- toList x ≡ toListOf (folded . here) (align x y) -- ≡ mapMaybe justHere (toList (align x y)) ---- -- And an addition property if f is Foldable, which -- tries to enforce align-feel: neither values are duplicated nor -- lost. -- --
-- toList x = toListOf (folded . here) (align x y) -- = mapMaybe justHere (toList (align x y)) --class Functor f => Semialign f -- | Analogous to zip, combines two structures by taking -- the union of their shapes and using These to hold the -- elements. align :: Semialign f => f a -> f b -> f (These a b) -- | Analogous to zipWith, combines two structures by -- taking the union of their shapes and combining the elements with the -- given function. alignWith :: Semialign f => (These a b -> c) -> f a -> f b -> f c -- | A unit of align. -- --
-- (`align` nil) ≡ fmap This -- (nil `align`) ≡ fmap That --class Semialign f => Align f -- | An empty structure. aligning with nil -- will produce a structure with the same shape and elements as the other -- input, modulo This or That. nil :: Align f => f a -- | Alignable functors supporting an "inverse" to align: splitting -- a union shape into its component parts. -- --
-- uncurry align (unalign xs) ≡ xs -- unalign (align xs ys) ≡ (xs, ys) ---- --
-- >>> unzipWith (unalign . Just) [This 'a', That 'b', These 'c' 'd'] -- ([Just 'a',Nothing,Just 'c'],[Nothing,Just 'b',Just 'd']) --class Semialign f => Unalign f unalign :: Unalign f => f (These a b) -> (f a, f b) unalignWith :: Unalign f => (c -> These a b) -> f c -> (f a, f b) -- | Functors supporting a zip operation that takes the intersection -- of non-uniform shapes. -- -- Minimal definition: either zip or zipWith. -- -- Idempotency -- --
-- join zip ≡ fmap (join (,)) ---- -- Commutativity -- --
-- zip x y ≡ swap <$> zip y x ---- -- Associativity -- --
-- zip x (zip y z) ≡ assoc <$> zip (zip x y) z ---- -- Absorption -- --
-- fst <$> zip xs (align xs ys) ≡ xs -- toThis <$> align xs (zip xs ys) ≡ This <$> xs -- where -- toThis (This a) = This a -- toThis (These a _) = This a -- toThis (That b) = That b ---- -- With -- --
-- zipWith f a b ≡ f <$> zip a b ---- -- Functoriality -- --
-- zip (f <$> x) (g <$> y) ≡ bimap f g <$> zip x y ---- -- Zippyness -- --
-- fmap fst (zip x x) ≡ x -- fmap snd (zip x x) ≡ x -- zip (fmap fst x) (fmap snd x) ≡ x ---- -- Distributivity -- --
-- align (zip xs ys) zs ≡ undistrThesePair <$> zip (align xs zs) (align ys zs) -- distrPairThese <$> zip (align xs ys) zs ≡ align (zip xs zs) (zip ys zs) -- zip (align xs ys) zs ≡ undistrPairThese <$> align (zip xs zs) (zip ys zs) ---- -- Note, the following doesn't hold: -- --
-- distrThesePair <$> align (zip xs ys) zs ≢ zip (align xs zs) (align ys zs) ---- -- when xs = [] and ys = zs = [0], then the left hand -- side is "only" [(That 0, That 0)], but the -- right hand side is [(That 0, These 0 0)]. class Semialign f => Zip f -- | Combines two structures by taking the intersection of their shapes and -- using pair to hold the elements. zip :: Zip f => f a -> f b -> f (a, b) -- | Combines two structures by taking the intersection of their shapes and -- combining the elements with the given function. zipWith :: Zip f => (a -> b -> c) -> f a -> f b -> f c -- | Zippable functors supporting left and right units -- -- Unit -- --
-- fst <$> zip xs (repeat y) ≡ xs -- snd <$> zip (repeat x) ys ≡ ys --class Zip f => Repeat f -- | A repeat structure. repeat :: Repeat f => a -> f a -- | Right inverse of zip. -- -- This class is definable for every Functor. See -- unzipDefault. -- --
-- uncurry zip (unzip xs) ≡ xs -- unzip (zip xs xs) ≡ (xs, xs) ---- -- Note: -- --
-- unzip (zip xs ys) ≢ (xs, _) or (_, ys) ---- -- For sequence-like types this holds, but for Map-like it doesn't. class Zip f => Unzip f unzipWith :: Unzip f => (c -> (a, b)) -> f c -> (f a, f b) unzip :: Unzip f => f (a, b) -> (f a, f b) unzipDefault :: Functor f => f (a, b) -> (f a, f b) -- | Align two structures and combine with <>. salign :: (Semialign f, Semigroup a) => f a -> f a -> f a -- | Align two structures as in zip, but filling in blanks with -- Nothing. padZip :: Semialign f => f a -> f b -> f (Maybe a, Maybe b) -- | Align two structures as in zipWith, but filling in blanks with -- Nothing. padZipWith :: Semialign f => (Maybe a -> Maybe b -> c) -> f a -> f b -> f c -- | Left-padded zip. lpadZip :: [a] -> [b] -> [(Maybe a, b)] -- | Left-padded zipWith. lpadZipWith :: (Maybe a -> b -> c) -> [a] -> [b] -> [c] -- | Right-padded zip. rpadZip :: [a] -> [b] -> [(a, Maybe b)] -- | Right-padded zipWith. rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c] alignVectorWith :: (Vector v a, Vector v b, Vector v c) => (These a b -> c) -> v a -> v b -> v c -- | These-based aligning and unaligning of functors with -- non-uniform shapes. -- -- For a traversals traversal of (bi)foldable (bi)functors through said -- functors see Data.Crosswalk. module Data.Align -- | Functors supporting an align operation that takes the union of -- non-uniform shapes. -- -- Minimal definition: either align or alignWith. -- --
-- join align ≡ fmap (join These) ---- -- Commutativity -- --
-- align x y ≡ swap <$> align y x ---- -- Associativity -- --
-- align x (align y z) ≡ assoc <$> align (align x y) z ---- -- With -- --
-- alignWith f a b ≡ f <$> align a b ---- -- Functoriality -- --
-- align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y ---- -- Alignedness, if f is Foldable -- --
-- toList x ≡ toListOf (folded . here) (align x y) -- ≡ mapMaybe justHere (toList (align x y)) ---- -- And an addition property if f is Foldable, which -- tries to enforce align-feel: neither values are duplicated nor -- lost. -- --
-- toList x = toListOf (folded . here) (align x y) -- = mapMaybe justHere (toList (align x y)) --class Functor f => Semialign f -- | Analogous to zip, combines two structures by taking -- the union of their shapes and using These to hold the -- elements. align :: Semialign f => f a -> f b -> f (These a b) -- | Analogous to zipWith, combines two structures by -- taking the union of their shapes and combining the elements with the -- given function. alignWith :: Semialign f => (These a b -> c) -> f a -> f b -> f c -- | A unit of align. -- --
-- (`align` nil) ≡ fmap This -- (nil `align`) ≡ fmap That --class Semialign f => Align f -- | An empty structure. aligning with nil -- will produce a structure with the same shape and elements as the other -- input, modulo This or That. nil :: Align f => f a -- | Alignable functors supporting an "inverse" to align: splitting -- a union shape into its component parts. -- --
-- uncurry align (unalign xs) ≡ xs -- unalign (align xs ys) ≡ (xs, ys) ---- --
-- >>> unzipWith (unalign . Just) [This 'a', That 'b', These 'c' 'd'] -- ([Just 'a',Nothing,Just 'c'],[Nothing,Just 'b',Just 'd']) --class Semialign f => Unalign f unalign :: Unalign f => f (These a b) -> (f a, f b) unalignWith :: Unalign f => (c -> These a b) -> f c -> (f a, f b) -- | Align two structures and combine with <>. salign :: (Semialign f, Semigroup a) => f a -> f a -> f a -- | Align two structures as in zip, but filling in blanks with -- Nothing. padZip :: Semialign f => f a -> f b -> f (Maybe a, Maybe b) -- | Align two structures as in zipWith, but filling in blanks with -- Nothing. padZipWith :: Semialign f => (Maybe a -> Maybe b -> c) -> f a -> f b -> f c -- | Left-padded zip. lpadZip :: [a] -> [b] -> [(Maybe a, b)] -- | Left-padded zipWith. lpadZipWith :: (Maybe a -> b -> c) -> [a] -> [b] -> [c] -- | Right-padded zip. rpadZip :: [a] -> [b] -> [(a, Maybe b)] -- | Right-padded zipWith. rpadZipWith :: (a -> Maybe b -> c) -> [a] -> [b] -> [c] alignVectorWith :: (Vector v a, Vector v b, Vector v c) => (These a b -> c) -> v a -> v b -> v c module Data.Crosswalk -- | Foldable functors supporting traversal through an alignable functor. -- -- Minimal definition: crosswalk or sequenceL. -- -- Laws: -- --
-- crosswalk (const nil) = const nil -- crosswalk f = sequenceL . fmap f --class (Functor t, Foldable t) => Crosswalk t crosswalk :: (Crosswalk t, Align f) => (a -> f b) -> t a -> f (t b) sequenceL :: (Crosswalk t, Align f) => t (f a) -> f (t a) -- | Bifoldable bifunctors supporting traversal through an alignable -- functor. -- -- Minimal definition: bicrosswalk or bisequenceL. -- -- Laws: -- --
-- bicrosswalk (const empty) (const empty) = const empty -- bicrosswalk f g = bisequenceL . bimap f g --class (Bifunctor t, Bifoldable t) => Bicrosswalk t bicrosswalk :: (Bicrosswalk t, Align f) => (a -> f c) -> (b -> f d) -> t a b -> f (t c d) bisequenceL :: (Bicrosswalk t, Align f) => t (f a) (f b) -> f (t a b) instance Data.Crosswalk.Bicrosswalk Data.Either.Either instance Data.Crosswalk.Bicrosswalk Data.These.These instance Data.Crosswalk.Crosswalk Data.Functor.Identity.Identity instance Data.Crosswalk.Crosswalk GHC.Maybe.Maybe instance Data.Crosswalk.Crosswalk [] instance Data.Crosswalk.Crosswalk Data.Sequence.Internal.Seq instance Data.Crosswalk.Crosswalk (Data.These.These a) instance Data.Crosswalk.Crosswalk Data.Vector.Vector instance Data.Crosswalk.Crosswalk ((,) a) instance (Data.Crosswalk.Crosswalk f, Data.Crosswalk.Crosswalk g) => Data.Crosswalk.Crosswalk (Data.Functor.Compose.Compose f g) -- | Zipping and unzipping of functors with non-uniform shapes. module Data.Zip -- | Functors supporting an align operation that takes the union of -- non-uniform shapes. -- -- Minimal definition: either align or alignWith. -- --
-- join align ≡ fmap (join These) ---- -- Commutativity -- --
-- align x y ≡ swap <$> align y x ---- -- Associativity -- --
-- align x (align y z) ≡ assoc <$> align (align x y) z ---- -- With -- --
-- alignWith f a b ≡ f <$> align a b ---- -- Functoriality -- --
-- align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y ---- -- Alignedness, if f is Foldable -- --
-- toList x ≡ toListOf (folded . here) (align x y) -- ≡ mapMaybe justHere (toList (align x y)) ---- -- And an addition property if f is Foldable, which -- tries to enforce align-feel: neither values are duplicated nor -- lost. -- --
-- toList x = toListOf (folded . here) (align x y) -- = mapMaybe justHere (toList (align x y)) --class Functor f => Semialign f -- | Analogous to zip, combines two structures by taking -- the union of their shapes and using These to hold the -- elements. align :: Semialign f => f a -> f b -> f (These a b) -- | Analogous to zipWith, combines two structures by -- taking the union of their shapes and combining the elements with the -- given function. alignWith :: Semialign f => (These a b -> c) -> f a -> f b -> f c -- | Functors supporting a zip operation that takes the intersection -- of non-uniform shapes. -- -- Minimal definition: either zip or zipWith. -- -- Idempotency -- --
-- join zip ≡ fmap (join (,)) ---- -- Commutativity -- --
-- zip x y ≡ swap <$> zip y x ---- -- Associativity -- --
-- zip x (zip y z) ≡ assoc <$> zip (zip x y) z ---- -- Absorption -- --
-- fst <$> zip xs (align xs ys) ≡ xs -- toThis <$> align xs (zip xs ys) ≡ This <$> xs -- where -- toThis (This a) = This a -- toThis (These a _) = This a -- toThis (That b) = That b ---- -- With -- --
-- zipWith f a b ≡ f <$> zip a b ---- -- Functoriality -- --
-- zip (f <$> x) (g <$> y) ≡ bimap f g <$> zip x y ---- -- Zippyness -- --
-- fmap fst (zip x x) ≡ x -- fmap snd (zip x x) ≡ x -- zip (fmap fst x) (fmap snd x) ≡ x ---- -- Distributivity -- --
-- align (zip xs ys) zs ≡ undistrThesePair <$> zip (align xs zs) (align ys zs) -- distrPairThese <$> zip (align xs ys) zs ≡ align (zip xs zs) (zip ys zs) -- zip (align xs ys) zs ≡ undistrPairThese <$> align (zip xs zs) (zip ys zs) ---- -- Note, the following doesn't hold: -- --
-- distrThesePair <$> align (zip xs ys) zs ≢ zip (align xs zs) (align ys zs) ---- -- when xs = [] and ys = zs = [0], then the left hand -- side is "only" [(That 0, That 0)], but the -- right hand side is [(That 0, These 0 0)]. class Semialign f => Zip f -- | Combines two structures by taking the intersection of their shapes and -- using pair to hold the elements. zip :: Zip f => f a -> f b -> f (a, b) -- | Combines two structures by taking the intersection of their shapes and -- combining the elements with the given function. zipWith :: Zip f => (a -> b -> c) -> f a -> f b -> f c -- | Zippable functors supporting left and right units -- -- Unit -- --
-- fst <$> zip xs (repeat y) ≡ xs -- snd <$> zip (repeat x) ys ≡ ys --class Zip f => Repeat f -- | A repeat structure. repeat :: Repeat f => a -> f a -- | Right inverse of zip. -- -- This class is definable for every Functor. See -- unzipDefault. -- --
-- uncurry zip (unzip xs) ≡ xs -- unzip (zip xs xs) ≡ (xs, xs) ---- -- Note: -- --
-- unzip (zip xs ys) ≢ (xs, _) or (_, ys) ---- -- For sequence-like types this holds, but for Map-like it doesn't. class Zip f => Unzip f unzipWith :: Unzip f => (c -> (a, b)) -> f c -> (f a, f b) unzip :: Unzip f => f (a, b) -> (f a, f b) unzipDefault :: Functor f => f (a, b) -> (f a, f b) newtype Zippy f a Zippy :: f a -> Zippy f a [getZippy] :: Zippy f a -> f a instance GHC.Base.Functor f => GHC.Base.Functor (Data.Zip.Zippy f) instance GHC.Read.Read (f a) => GHC.Read.Read (Data.Zip.Zippy f a) instance GHC.Show.Show (f a) => GHC.Show.Show (Data.Zip.Zippy f a) instance GHC.Classes.Ord (f a) => GHC.Classes.Ord (Data.Zip.Zippy f a) instance GHC.Classes.Eq (f a) => GHC.Classes.Eq (Data.Zip.Zippy f a) instance (Data.Semialign.Internal.Zip f, GHC.Base.Semigroup a) => GHC.Base.Semigroup (Data.Zip.Zippy f a) instance (Data.Semialign.Internal.Repeat f, GHC.Base.Monoid a) => GHC.Base.Monoid (Data.Zip.Zippy f a) instance Data.Semialign.Internal.Zip f => Data.Functor.Bind.Class.Apply (Data.Zip.Zippy f) instance Data.Semialign.Internal.Repeat f => GHC.Base.Applicative (Data.Zip.Zippy f)