-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Typeclasses augmented with a phantom type parameter -- -- Provides alternative versions of common typeclasses, augmented with a -- phantom that allows multiple instances to be specified in the case -- where a type has more than one candidate instance for the original -- class. @package multi-instance @version 0.0.0.2 -- | The MultiInstance module provides alternative versions of -- common typeclasses, augmented with a phantom type parameter -- x. The purpose of this is to deal with the case where a type -- has more than one candidate instance for the original, unaugmented -- class. -- --

Example: Integer sum and product

-- -- The canonical example of this predicament is selecting the monoid -- instance for a type which forms a ring (and thus has at least two -- strong candidates for selection as the monoid), such as -- Integer. This therefore gives rise to the Sum and -- Product newtype wrappers, corresponding to the additive and -- multiplicative monoids respectively. -- -- The traditional fold-based summation of a list of integers -- looks like this: -- --
--   >>> import Data.Foldable (fold)
--   
--   >>> import Data.Monoid (Sum (..))
--   
--   >>> getSum (fold [Sum 2, Sum 3, Sum 5]) :: Integer
--   10
--   
-- -- By replacing fold with multi'fold, whose constraint is -- MultiMonoid rather than Monoid, we can write the same -- thing without the newtype wrapper: -- --
--   >>> :set -XFlexibleContexts -XTypeApplications
--   
--   >>> multi'fold @Addition [2, 3, 5] :: Integer
--   10
--   
-- --

The typeclasses

-- -- The current list of "multi-instance" typeclasses: -- -- -- --

The phantom types

-- -- The current list of phantom types used for the x type -- parameter: -- -- module MultiInstance -- | Akin to the Semigroup class, but with the addition of the -- phantom type parameter x which lets you specify which -- semigroup to use. -- -- For example, the integers form a semigroup via either Addition -- or Multiplication: -- --
--   >>> :set -XFlexibleContexts -XTypeApplications
--   
--   >>> multi'append @Addition 6 7 :: Integer
--   13
--   
--   >>> multi'append @Multiplication 6 7 :: Integer
--   42
--   
--   >>> multi'stimes @Addition (3 :: Natural) (4 :: Integer)
--   12
--   
--   >>> multi'stimes @Multiplication (3 :: Natural) (4 :: Integer)
--   64
--   
class MultiSemigroup x a -- | An associative operation. -- -- Akin to <>. multi'append :: MultiSemigroup x a => a -> a -> a -- | Reduce a non-empty list with multi'append. -- -- Akin to sconcat. multi'sconcat :: MultiSemigroup x a => NonEmpty a -> a -- | Repeat a value n times. -- -- Akin to stimes. multi'stimes :: (MultiSemigroup x a, Integral b) => b -> a -> a -- | Akin to the Monoid class, but with the addition of the phantom -- type parameter x which lets you specify which monoid -- to use. -- -- For example, the integers form a monoid via either Addition or -- Multiplication: -- --
--   >>> :set -XFlexibleContexts -XTypeApplications
--   
--   >>> multi'fold @Addition [] :: Integer
--   0
--   
--   >>> multi'fold @Addition [2, 3, 5] :: Integer
--   10
--   
--   >>> multi'fold @Multiplication [] :: Integer
--   1
--   
--   >>> multi'fold @Multiplication [2, 3, 5] :: Integer
--   30
--   
class MultiSemigroup x a => MultiMonoid x a -- | Identity of multi'append. -- -- Akin to mempty. multi'empty :: MultiMonoid x a => a -- | Fold a list using the monoid. -- -- Akin to mconcat. multi'mconcat :: MultiMonoid x a => [a] -> a data Default data Conjunction data Disjunction type Addition = Disjunction type Multiplication = Conjunction -- | The sum of the numbers in a structure. -- -- Equivalent to multi'fold @Addition. -- -- Akin to sum. multi'sum :: (Foldable t, MultiMonoid Addition a) => t a -> a -- | The product of the numbers of a structure. -- -- Equivalent to multi'fold -- @Multiplication. -- -- Akin to product. multi'product :: (Foldable t, MultiMonoid Multiplication a) => t a -> a type And = Conjunction type Or = Disjunction -- | The conjunction of a container of Bools. -- -- Equivalent to multi'fold @And. -- -- Akin to and. multi'and :: (Foldable t, MultiMonoid And a) => t a -> a -- | The disjunction of a container of Bools. -- -- Equivalent to multi'fold @Or. -- -- Akin to or. multi'or :: (Foldable t, MultiMonoid Or a) => t a -> a -- | Determines whether any element of the structure satisfies the -- predicate. -- -- Equivalent to multi'foldMap @Or. -- -- Akin to any. multi'any :: (Foldable t, MultiMonoid Or b) => (a -> b) -> t a -> b -- | Determines whether all elements of the structure satisfy the -- predicate. -- -- Equivalent to multi'foldMap @And. -- -- Akin to all. multi'all :: Foldable t => (a -> Bool) -> t a -> Bool data Min data Max data MinMaybe data MaxMaybe data First data Last data ArrowComposition data MultiDual a -- | Combine the elements of a structure using a monoid. -- -- Akin to fold. multi'fold :: forall x t m. (MultiMonoid x m, Foldable t) => t m -> m -- | Map each element of the structure to a monoid, and combine the -- results. -- -- Akin to foldMap. multi'foldMap :: forall x t m a. (MultiMonoid x m, Foldable t) => (a -> m) -> t a -> m -- | Takes a predicate and a structure and returns the leftmost element of -- the structure matching the predicate, or Nothing if there is no -- such element. -- -- Akin to find. multi'find :: Foldable t => (a -> Bool) -> t a -> Maybe a instance MultiInstance.MultiSemigroup x a => MultiInstance.MultiSemigroup (MultiInstance.MultiDual x) a instance MultiInstance.MultiMonoid x a => MultiInstance.MultiMonoid (MultiInstance.MultiDual x) a instance MultiInstance.MultiSemigroup MultiInstance.ArrowComposition (a -> a) instance MultiInstance.MultiMonoid MultiInstance.ArrowComposition (a -> a) instance GHC.Base.Monad m => MultiInstance.MultiSemigroup MultiInstance.ArrowComposition (Control.Arrow.Kleisli m a a) instance GHC.Base.Monad m => MultiInstance.MultiMonoid MultiInstance.ArrowComposition (Control.Arrow.Kleisli m a a) instance MultiInstance.MultiSemigroup MultiInstance.Last (GHC.Base.Maybe a) instance MultiInstance.MultiMonoid MultiInstance.Last (GHC.Base.Maybe a) instance MultiInstance.MultiSemigroup MultiInstance.First (GHC.Base.Maybe a) instance MultiInstance.MultiMonoid MultiInstance.First (GHC.Base.Maybe a) instance GHC.Classes.Ord a => MultiInstance.MultiSemigroup MultiInstance.MaxMaybe (GHC.Base.Maybe a) instance GHC.Classes.Ord a => MultiInstance.MultiMonoid MultiInstance.MaxMaybe (GHC.Base.Maybe a) instance GHC.Classes.Ord a => MultiInstance.MultiSemigroup MultiInstance.MinMaybe (GHC.Base.Maybe a) instance GHC.Classes.Ord a => MultiInstance.MultiMonoid MultiInstance.MinMaybe (GHC.Base.Maybe a) instance GHC.Classes.Ord a => MultiInstance.MultiSemigroup MultiInstance.Max a instance GHC.Classes.Ord a => MultiInstance.MultiSemigroup MultiInstance.Min a instance MultiInstance.MultiSemigroup MultiInstance.Multiplication GHC.Types.Int instance MultiInstance.MultiSemigroup MultiInstance.Multiplication GHC.Integer.Type.Integer instance MultiInstance.MultiSemigroup MultiInstance.Multiplication GHC.Natural.Natural instance MultiInstance.MultiMonoid MultiInstance.Multiplication GHC.Types.Int instance MultiInstance.MultiMonoid MultiInstance.Multiplication GHC.Integer.Type.Integer instance MultiInstance.MultiMonoid MultiInstance.Multiplication GHC.Natural.Natural instance MultiInstance.MultiSemigroup MultiInstance.Addition GHC.Types.Int instance MultiInstance.MultiSemigroup MultiInstance.Addition GHC.Integer.Type.Integer instance MultiInstance.MultiSemigroup MultiInstance.Addition GHC.Natural.Natural instance MultiInstance.MultiMonoid MultiInstance.Addition GHC.Types.Int instance MultiInstance.MultiMonoid MultiInstance.Addition GHC.Integer.Type.Integer instance MultiInstance.MultiMonoid MultiInstance.Addition GHC.Natural.Natural instance MultiInstance.MultiSemigroup MultiInstance.Addition [a] instance MultiInstance.MultiMonoid MultiInstance.Addition [a] instance MultiInstance.MultiSemigroup MultiInstance.Addition (Data.List.NonEmpty.NonEmpty a) instance MultiInstance.MultiSemigroup MultiInstance.Or GHC.Types.Bool instance MultiInstance.MultiMonoid MultiInstance.Or GHC.Types.Bool instance MultiInstance.MultiSemigroup MultiInstance.And GHC.Types.Bool instance MultiInstance.MultiMonoid MultiInstance.And GHC.Types.Bool instance Data.Semigroup.Semigroup a => MultiInstance.MultiSemigroup MultiInstance.Default a instance (Data.Semigroup.Semigroup a, GHC.Base.Monoid a) => MultiInstance.MultiMonoid MultiInstance.Default a instance MultiInstance.MultiMonoid x () instance MultiInstance.MultiSemigroup x ()