{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- | Auxiliary definitions for 'Semigroup'
--
-- This module provides some @newtype@ wrappers and helpers which are
-- reexported from the "Data.Semigroup" module or imported directly
-- by some other modules.
--
-- This module also provides internal definitions related to the
-- 'Semigroup' class some.
--
-- This module exists mostly to simplify or workaround import-graph
-- issues; there is also a .hs-boot file to allow "GHC.Base" and other
-- modules to import method default implementations for 'stimes'
--
-- @since 4.11.0.0
module Data.Semigroup.Internal where

import GHC.Base hiding (Any)
import GHC.Enum
import qualified GHC.List as List
import GHC.Num
import GHC.Read
import GHC.Show
import GHC.Generics
import GHC.Real

-- | This is a valid definition of 'stimes' for an idempotent 'Semigroup'.
--
-- When @x <> x = x@, this definition should be preferred, because it
-- works in \(\mathcal{O}(1)\) rather than \(\mathcal{O}(\log n)\).
stimesIdempotent :: Integral b => b -> a -> a
stimesIdempotent :: forall b a. Integral b => b -> a -> a
stimesIdempotent b
n a
x
  | b
n b -> b -> Bool
forall a. Ord a => a -> a -> Bool
<= b
0 = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimesIdempotent: positive multiplier expected"
  | Bool
otherwise = a
x

-- | This is a valid definition of 'stimes' for an idempotent 'Monoid'.
--
-- When @mappend x x = x@, this definition should be preferred, because it
-- works in \(\mathcal{O}(1)\) rather than \(\mathcal{O}(\log n)\)
stimesIdempotentMonoid :: (Integral b, Monoid a) => b -> a -> a
stimesIdempotentMonoid :: forall b a. (Integral b, Monoid a) => b -> a -> a
stimesIdempotentMonoid b
n a
x = case b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare b
n b
0 of
  Ordering
LT -> [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimesIdempotentMonoid: negative multiplier"
  Ordering
EQ -> a
forall a. Monoid a => a
mempty
  Ordering
GT -> a
x

-- | This is a valid definition of 'stimes' for a 'Monoid'.
--
-- Unlike the default definition of 'stimes', it is defined for 0
-- and so it should be preferred where possible.
stimesMonoid :: (Integral b, Monoid a) => b -> a -> a
stimesMonoid :: forall b a. (Integral b, Monoid a) => b -> a -> a
stimesMonoid b
n a
x0 = case b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare b
n b
0 of
  Ordering
LT -> [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimesMonoid: negative multiplier"
  Ordering
EQ -> a
forall a. Monoid a => a
mempty
  Ordering
GT -> a -> b -> a
forall {a} {t}. (Integral a, Monoid t) => t -> a -> t
f a
x0 b
n
    where
      f :: t -> a -> t
f t
x a
y
        | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t
f (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2)
        | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x
        | Bool
otherwise = t -> a -> t -> t
forall {a} {t}. (Integral a, Monoid t) => t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
x               -- See Note [Half of y - 1]
      g :: t -> a -> t -> t
g t
x a
y t
z
        | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
z
        | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
z
        | Bool
otherwise = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) (t
x t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` t
z) -- See Note [Half of y - 1]

-- this is used by the class definition in GHC.Base;
-- it lives here to avoid cycles
stimesDefault :: (Integral b, Semigroup a) => b -> a -> a
stimesDefault :: forall b a. (Integral b, Semigroup a) => b -> a -> a
stimesDefault b
y0 a
x0
  | b
y0 b -> b -> Bool
forall a. Ord a => a -> a -> Bool
<= b
0   = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimes: positive multiplier expected"
  | Bool
otherwise = a -> b -> a
forall {a} {t}. (Integral a, Semigroup t) => t -> a -> t
f a
x0 b
y0
  where
    f :: t -> a -> t
f t
x a
y
      | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t
f (t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2)
      | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x
      | Bool
otherwise = t -> a -> t -> t
forall {a} {t}. (Integral a, Semigroup t) => t -> a -> t -> t
g (t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
x        -- See Note [Half of y - 1]
    g :: t -> a -> t -> t
g t
x a
y t
z
      | a -> Bool
forall a. Integral a => a -> Bool
even a
y = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) t
z
      | a
y a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
1 = t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
z
      | Bool
otherwise = t -> a -> t -> t
g (t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
x) (a
y a -> a -> a
forall a. Integral a => a -> a -> a
`quot` a
2) (t
x t -> t -> t
forall a. Semigroup a => a -> a -> a
<> t
z) -- See Note [Half of y - 1]

{- Note [Half of y - 1]
   ~~~~~~~~~~~~~~~~~~~~~
   Since y is guaranteed to be odd and positive here,
   half of y - 1 can be computed as y `quot` 2, optimising subtraction away.
-}

stimesMaybe :: (Integral b, Semigroup a) => b -> Maybe a -> Maybe a
stimesMaybe :: forall b a. (Integral b, Semigroup a) => b -> Maybe a -> Maybe a
stimesMaybe b
_ Maybe a
Nothing = Maybe a
forall a. Maybe a
Nothing
stimesMaybe b
n (Just a
a) = case b -> b -> Ordering
forall a. Ord a => a -> a -> Ordering
compare b
n b
0 of
    Ordering
LT -> [Char] -> Maybe a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimes: Maybe, negative multiplier"
    Ordering
EQ -> Maybe a
forall a. Maybe a
Nothing
    Ordering
GT -> a -> Maybe a
forall a. a -> Maybe a
Just (b -> a -> a
forall b. Integral b => b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n a
a)

stimesList  :: Integral b => b -> [a] -> [a]
stimesList :: forall b a. Integral b => b -> [a] -> [a]
stimesList b
n [a]
x
  | b
n b -> b -> Bool
forall a. Ord a => a -> a -> Bool
< b
0 = [Char] -> [a]
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"stimes: [], negative multiplier"
  | Bool
otherwise = b -> [a]
forall {t}. (Eq t, Num t) => t -> [a]
rep b
n
  where
    rep :: t -> [a]
rep t
0 = []
    rep t
i = [a]
x [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ t -> [a]
rep (t
i t -> t -> t
forall a. Num a => a -> a -> a
- t
1)

-- | The dual of a 'Monoid', obtained by swapping the arguments of 'mappend'.
--
-- >>> getDual (mappend (Dual "Hello") (Dual "World"))
-- "WorldHello"
newtype Dual a = Dual { forall a. Dual a -> a
getDual :: a }
        deriving ( Dual a -> Dual a -> Bool
(Dual a -> Dual a -> Bool)
-> (Dual a -> Dual a -> Bool) -> Eq (Dual a)
forall a. Eq a => Dual a -> Dual a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Dual a -> Dual a -> Bool
== :: Dual a -> Dual a -> Bool
$c/= :: forall a. Eq a => Dual a -> Dual a -> Bool
/= :: Dual a -> Dual a -> Bool
Eq       -- ^ @since 2.01
                 , Eq (Dual a)
Eq (Dual a)
-> (Dual a -> Dual a -> Ordering)
-> (Dual a -> Dual a -> Bool)
-> (Dual a -> Dual a -> Bool)
-> (Dual a -> Dual a -> Bool)
-> (Dual a -> Dual a -> Bool)
-> (Dual a -> Dual a -> Dual a)
-> (Dual a -> Dual a -> Dual a)
-> Ord (Dual a)
Dual a -> Dual a -> Bool
Dual a -> Dual a -> Ordering
Dual a -> Dual a -> Dual a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Dual a)
forall a. Ord a => Dual a -> Dual a -> Bool
forall a. Ord a => Dual a -> Dual a -> Ordering
forall a. Ord a => Dual a -> Dual a -> Dual a
$ccompare :: forall a. Ord a => Dual a -> Dual a -> Ordering
compare :: Dual a -> Dual a -> Ordering
$c< :: forall a. Ord a => Dual a -> Dual a -> Bool
< :: Dual a -> Dual a -> Bool
$c<= :: forall a. Ord a => Dual a -> Dual a -> Bool
<= :: Dual a -> Dual a -> Bool
$c> :: forall a. Ord a => Dual a -> Dual a -> Bool
> :: Dual a -> Dual a -> Bool
$c>= :: forall a. Ord a => Dual a -> Dual a -> Bool
>= :: Dual a -> Dual a -> Bool
$cmax :: forall a. Ord a => Dual a -> Dual a -> Dual a
max :: Dual a -> Dual a -> Dual a
$cmin :: forall a. Ord a => Dual a -> Dual a -> Dual a
min :: Dual a -> Dual a -> Dual a
Ord      -- ^ @since 2.01
                 , ReadPrec [Dual a]
ReadPrec (Dual a)
Int -> ReadS (Dual a)
ReadS [Dual a]
(Int -> ReadS (Dual a))
-> ReadS [Dual a]
-> ReadPrec (Dual a)
-> ReadPrec [Dual a]
-> Read (Dual a)
forall a. Read a => ReadPrec [Dual a]
forall a. Read a => ReadPrec (Dual a)
forall a. Read a => Int -> ReadS (Dual a)
forall a. Read a => ReadS [Dual a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Dual a)
readsPrec :: Int -> ReadS (Dual a)
$creadList :: forall a. Read a => ReadS [Dual a]
readList :: ReadS [Dual a]
$creadPrec :: forall a. Read a => ReadPrec (Dual a)
readPrec :: ReadPrec (Dual a)
$creadListPrec :: forall a. Read a => ReadPrec [Dual a]
readListPrec :: ReadPrec [Dual a]
Read     -- ^ @since 2.01
                 , Int -> Dual a -> ShowS
[Dual a] -> ShowS
Dual a -> [Char]
(Int -> Dual a -> ShowS)
-> (Dual a -> [Char]) -> ([Dual a] -> ShowS) -> Show (Dual a)
forall a. Show a => Int -> Dual a -> ShowS
forall a. Show a => [Dual a] -> ShowS
forall a. Show a => Dual a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Dual a -> ShowS
showsPrec :: Int -> Dual a -> ShowS
$cshow :: forall a. Show a => Dual a -> [Char]
show :: Dual a -> [Char]
$cshowList :: forall a. Show a => [Dual a] -> ShowS
showList :: [Dual a] -> ShowS
Show     -- ^ @since 2.01
                 , Dual a
Dual a -> Dual a -> Bounded (Dual a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Dual a
$cminBound :: forall a. Bounded a => Dual a
minBound :: Dual a
$cmaxBound :: forall a. Bounded a => Dual a
maxBound :: Dual a
Bounded  -- ^ @since 2.01
                 , (forall x. Dual a -> Rep (Dual a) x)
-> (forall x. Rep (Dual a) x -> Dual a) -> Generic (Dual a)
forall x. Rep (Dual a) x -> Dual a
forall x. Dual a -> Rep (Dual a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Dual a) x -> Dual a
forall a x. Dual a -> Rep (Dual a) x
$cfrom :: forall a x. Dual a -> Rep (Dual a) x
from :: forall x. Dual a -> Rep (Dual a) x
$cto :: forall a x. Rep (Dual a) x -> Dual a
to :: forall x. Rep (Dual a) x -> Dual a
Generic  -- ^ @since 4.7.0.0
                 , (forall a. Dual a -> Rep1 Dual a)
-> (forall a. Rep1 Dual a -> Dual a) -> Generic1 Dual
forall a. Rep1 Dual a -> Dual a
forall a. Dual a -> Rep1 Dual a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. Dual a -> Rep1 Dual a
from1 :: forall a. Dual a -> Rep1 Dual a
$cto1 :: forall a. Rep1 Dual a -> Dual a
to1 :: forall a. Rep1 Dual a -> Dual a
Generic1 -- ^ @since 4.7.0.0
                 )

-- | @since 4.9.0.0
instance Semigroup a => Semigroup (Dual a) where
        Dual a
a <> :: Dual a -> Dual a -> Dual a
<> Dual a
b = a -> Dual a
forall a. a -> Dual a
Dual (a
b a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
a)
        stimes :: forall b. Integral b => b -> Dual a -> Dual a
stimes b
n (Dual a
a) = a -> Dual a
forall a. a -> Dual a
Dual (b -> a -> a
forall b. Integral b => b -> a -> a
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n a
a)

-- | @since 2.01
instance Monoid a => Monoid (Dual a) where
        mempty :: Dual a
mempty = a -> Dual a
forall a. a -> Dual a
Dual a
forall a. Monoid a => a
mempty

-- | @since 4.8.0.0
instance Functor Dual where
    fmap :: forall a b. (a -> b) -> Dual a -> Dual b
fmap     = (a -> b) -> Dual a -> Dual b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Applicative Dual where
    pure :: forall a. a -> Dual a
pure     = a -> Dual a
forall a. a -> Dual a
Dual
    <*> :: forall a b. Dual (a -> b) -> Dual a -> Dual b
(<*>)    = Dual (a -> b) -> Dual a -> Dual b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Monad Dual where
    Dual a
m >>= :: forall a b. Dual a -> (a -> Dual b) -> Dual b
>>= a -> Dual b
k  = a -> Dual b
k (Dual a -> a
forall a. Dual a -> a
getDual Dual a
m)

-- | The monoid of endomorphisms under composition.
--
-- >>> let computation = Endo ("Hello, " ++) <> Endo (++ "!")
-- >>> appEndo computation "Haskell"
-- "Hello, Haskell!"
newtype Endo a = Endo { forall a. Endo a -> a -> a
appEndo :: a -> a }
               deriving ( (forall x. Endo a -> Rep (Endo a) x)
-> (forall x. Rep (Endo a) x -> Endo a) -> Generic (Endo a)
forall x. Rep (Endo a) x -> Endo a
forall x. Endo a -> Rep (Endo a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Endo a) x -> Endo a
forall a x. Endo a -> Rep (Endo a) x
$cfrom :: forall a x. Endo a -> Rep (Endo a) x
from :: forall x. Endo a -> Rep (Endo a) x
$cto :: forall a x. Rep (Endo a) x -> Endo a
to :: forall x. Rep (Endo a) x -> Endo a
Generic -- ^ @since 4.7.0.0
                        )

-- | @since 4.9.0.0
instance Semigroup (Endo a) where
        <> :: Endo a -> Endo a -> Endo a
(<>) = ((a -> a) -> (a -> a) -> a -> a) -> Endo a -> Endo a -> Endo a
forall a b. Coercible a b => a -> b
coerce ((a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) :: (a -> a) -> (a -> a) -> (a -> a))
        stimes :: forall b. Integral b => b -> Endo a -> Endo a
stimes = b -> Endo a -> Endo a
forall b a. (Integral b, Monoid a) => b -> a -> a
stimesMonoid

-- | @since 2.01
instance Monoid (Endo a) where
        mempty :: Endo a
mempty = (a -> a) -> Endo a
forall a. (a -> a) -> Endo a
Endo a -> a
forall a. a -> a
id

-- | Boolean monoid under conjunction ('&&').
--
-- >>> getAll (All True <> mempty <> All False)
-- False
--
-- >>> getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
-- False
newtype All = All { All -> Bool
getAll :: Bool }
        deriving ( All -> All -> Bool
(All -> All -> Bool) -> (All -> All -> Bool) -> Eq All
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: All -> All -> Bool
== :: All -> All -> Bool
$c/= :: All -> All -> Bool
/= :: All -> All -> Bool
Eq      -- ^ @since 2.01
                 , Eq All
Eq All
-> (All -> All -> Ordering)
-> (All -> All -> Bool)
-> (All -> All -> Bool)
-> (All -> All -> Bool)
-> (All -> All -> Bool)
-> (All -> All -> All)
-> (All -> All -> All)
-> Ord All
All -> All -> Bool
All -> All -> Ordering
All -> All -> All
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: All -> All -> Ordering
compare :: All -> All -> Ordering
$c< :: All -> All -> Bool
< :: All -> All -> Bool
$c<= :: All -> All -> Bool
<= :: All -> All -> Bool
$c> :: All -> All -> Bool
> :: All -> All -> Bool
$c>= :: All -> All -> Bool
>= :: All -> All -> Bool
$cmax :: All -> All -> All
max :: All -> All -> All
$cmin :: All -> All -> All
min :: All -> All -> All
Ord     -- ^ @since 2.01
                 , ReadPrec [All]
ReadPrec All
Int -> ReadS All
ReadS [All]
(Int -> ReadS All)
-> ReadS [All] -> ReadPrec All -> ReadPrec [All] -> Read All
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS All
readsPrec :: Int -> ReadS All
$creadList :: ReadS [All]
readList :: ReadS [All]
$creadPrec :: ReadPrec All
readPrec :: ReadPrec All
$creadListPrec :: ReadPrec [All]
readListPrec :: ReadPrec [All]
Read    -- ^ @since 2.01
                 , Int -> All -> ShowS
[All] -> ShowS
All -> [Char]
(Int -> All -> ShowS)
-> (All -> [Char]) -> ([All] -> ShowS) -> Show All
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> All -> ShowS
showsPrec :: Int -> All -> ShowS
$cshow :: All -> [Char]
show :: All -> [Char]
$cshowList :: [All] -> ShowS
showList :: [All] -> ShowS
Show    -- ^ @since 2.01
                 , All
All -> All -> Bounded All
forall a. a -> a -> Bounded a
$cminBound :: All
minBound :: All
$cmaxBound :: All
maxBound :: All
Bounded -- ^ @since 2.01
                 , (forall x. All -> Rep All x)
-> (forall x. Rep All x -> All) -> Generic All
forall x. Rep All x -> All
forall x. All -> Rep All x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. All -> Rep All x
from :: forall x. All -> Rep All x
$cto :: forall x. Rep All x -> All
to :: forall x. Rep All x -> All
Generic -- ^ @since 4.7.0.0
                 )

-- | @since 4.9.0.0
instance Semigroup All where
        <> :: All -> All -> All
(<>) = (Bool -> Bool -> Bool) -> All -> All -> All
forall a b. Coercible a b => a -> b
coerce Bool -> Bool -> Bool
(&&)
        stimes :: forall b. Integral b => b -> All -> All
stimes = b -> All -> All
forall b a. (Integral b, Monoid a) => b -> a -> a
stimesIdempotentMonoid

-- | @since 2.01
instance Monoid All where
        mempty :: All
mempty = Bool -> All
All Bool
True

-- | Boolean monoid under disjunction ('||').
--
-- >>> getAny (Any True <> mempty <> Any False)
-- True
--
-- >>> getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
-- True
newtype Any = Any { Any -> Bool
getAny :: Bool }
        deriving ( Any -> Any -> Bool
(Any -> Any -> Bool) -> (Any -> Any -> Bool) -> Eq Any
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Any -> Any -> Bool
== :: Any -> Any -> Bool
$c/= :: Any -> Any -> Bool
/= :: Any -> Any -> Bool
Eq      -- ^ @since 2.01
                 , Eq Any
Eq Any
-> (Any -> Any -> Ordering)
-> (Any -> Any -> Bool)
-> (Any -> Any -> Bool)
-> (Any -> Any -> Bool)
-> (Any -> Any -> Bool)
-> (Any -> Any -> Any)
-> (Any -> Any -> Any)
-> Ord Any
Any -> Any -> Bool
Any -> Any -> Ordering
Any -> Any -> Any
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Any -> Any -> Ordering
compare :: Any -> Any -> Ordering
$c< :: Any -> Any -> Bool
< :: Any -> Any -> Bool
$c<= :: Any -> Any -> Bool
<= :: Any -> Any -> Bool
$c> :: Any -> Any -> Bool
> :: Any -> Any -> Bool
$c>= :: Any -> Any -> Bool
>= :: Any -> Any -> Bool
$cmax :: Any -> Any -> Any
max :: Any -> Any -> Any
$cmin :: Any -> Any -> Any
min :: Any -> Any -> Any
Ord     -- ^ @since 2.01
                 , ReadPrec [Any]
ReadPrec Any
Int -> ReadS Any
ReadS [Any]
(Int -> ReadS Any)
-> ReadS [Any] -> ReadPrec Any -> ReadPrec [Any] -> Read Any
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Any
readsPrec :: Int -> ReadS Any
$creadList :: ReadS [Any]
readList :: ReadS [Any]
$creadPrec :: ReadPrec Any
readPrec :: ReadPrec Any
$creadListPrec :: ReadPrec [Any]
readListPrec :: ReadPrec [Any]
Read    -- ^ @since 2.01
                 , Int -> Any -> ShowS
[Any] -> ShowS
Any -> [Char]
(Int -> Any -> ShowS)
-> (Any -> [Char]) -> ([Any] -> ShowS) -> Show Any
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Any -> ShowS
showsPrec :: Int -> Any -> ShowS
$cshow :: Any -> [Char]
show :: Any -> [Char]
$cshowList :: [Any] -> ShowS
showList :: [Any] -> ShowS
Show    -- ^ @since 2.01
                 , Any
Any -> Any -> Bounded Any
forall a. a -> a -> Bounded a
$cminBound :: Any
minBound :: Any
$cmaxBound :: Any
maxBound :: Any
Bounded -- ^ @since 2.01
                 , (forall x. Any -> Rep Any x)
-> (forall x. Rep Any x -> Any) -> Generic Any
forall x. Rep Any x -> Any
forall x. Any -> Rep Any x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Any -> Rep Any x
from :: forall x. Any -> Rep Any x
$cto :: forall x. Rep Any x -> Any
to :: forall x. Rep Any x -> Any
Generic -- ^ @since 4.7.0.0
                 )

-- | @since 4.9.0.0
instance Semigroup Any where
        <> :: Any -> Any -> Any
(<>) = (Bool -> Bool -> Bool) -> Any -> Any -> Any
forall a b. Coercible a b => a -> b
coerce Bool -> Bool -> Bool
(||)
        stimes :: forall b. Integral b => b -> Any -> Any
stimes = b -> Any -> Any
forall b a. (Integral b, Monoid a) => b -> a -> a
stimesIdempotentMonoid

-- | @since 2.01
instance Monoid Any where
        mempty :: Any
mempty = Bool -> Any
Any Bool
False

-- | Monoid under addition.
--
-- >>> getSum (Sum 1 <> Sum 2 <> mempty)
-- 3
newtype Sum a = Sum { forall a. Sum a -> a
getSum :: a }
        deriving ( Sum a -> Sum a -> Bool
(Sum a -> Sum a -> Bool) -> (Sum a -> Sum a -> Bool) -> Eq (Sum a)
forall a. Eq a => Sum a -> Sum a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Sum a -> Sum a -> Bool
== :: Sum a -> Sum a -> Bool
$c/= :: forall a. Eq a => Sum a -> Sum a -> Bool
/= :: Sum a -> Sum a -> Bool
Eq       -- ^ @since 2.01
                 , Eq (Sum a)
Eq (Sum a)
-> (Sum a -> Sum a -> Ordering)
-> (Sum a -> Sum a -> Bool)
-> (Sum a -> Sum a -> Bool)
-> (Sum a -> Sum a -> Bool)
-> (Sum a -> Sum a -> Bool)
-> (Sum a -> Sum a -> Sum a)
-> (Sum a -> Sum a -> Sum a)
-> Ord (Sum a)
Sum a -> Sum a -> Bool
Sum a -> Sum a -> Ordering
Sum a -> Sum a -> Sum a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Sum a)
forall a. Ord a => Sum a -> Sum a -> Bool
forall a. Ord a => Sum a -> Sum a -> Ordering
forall a. Ord a => Sum a -> Sum a -> Sum a
$ccompare :: forall a. Ord a => Sum a -> Sum a -> Ordering
compare :: Sum a -> Sum a -> Ordering
$c< :: forall a. Ord a => Sum a -> Sum a -> Bool
< :: Sum a -> Sum a -> Bool
$c<= :: forall a. Ord a => Sum a -> Sum a -> Bool
<= :: Sum a -> Sum a -> Bool
$c> :: forall a. Ord a => Sum a -> Sum a -> Bool
> :: Sum a -> Sum a -> Bool
$c>= :: forall a. Ord a => Sum a -> Sum a -> Bool
>= :: Sum a -> Sum a -> Bool
$cmax :: forall a. Ord a => Sum a -> Sum a -> Sum a
max :: Sum a -> Sum a -> Sum a
$cmin :: forall a. Ord a => Sum a -> Sum a -> Sum a
min :: Sum a -> Sum a -> Sum a
Ord      -- ^ @since 2.01
                 , ReadPrec [Sum a]
ReadPrec (Sum a)
Int -> ReadS (Sum a)
ReadS [Sum a]
(Int -> ReadS (Sum a))
-> ReadS [Sum a]
-> ReadPrec (Sum a)
-> ReadPrec [Sum a]
-> Read (Sum a)
forall a. Read a => ReadPrec [Sum a]
forall a. Read a => ReadPrec (Sum a)
forall a. Read a => Int -> ReadS (Sum a)
forall a. Read a => ReadS [Sum a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Sum a)
readsPrec :: Int -> ReadS (Sum a)
$creadList :: forall a. Read a => ReadS [Sum a]
readList :: ReadS [Sum a]
$creadPrec :: forall a. Read a => ReadPrec (Sum a)
readPrec :: ReadPrec (Sum a)
$creadListPrec :: forall a. Read a => ReadPrec [Sum a]
readListPrec :: ReadPrec [Sum a]
Read     -- ^ @since 2.01
                 , Int -> Sum a -> ShowS
[Sum a] -> ShowS
Sum a -> [Char]
(Int -> Sum a -> ShowS)
-> (Sum a -> [Char]) -> ([Sum a] -> ShowS) -> Show (Sum a)
forall a. Show a => Int -> Sum a -> ShowS
forall a. Show a => [Sum a] -> ShowS
forall a. Show a => Sum a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Sum a -> ShowS
showsPrec :: Int -> Sum a -> ShowS
$cshow :: forall a. Show a => Sum a -> [Char]
show :: Sum a -> [Char]
$cshowList :: forall a. Show a => [Sum a] -> ShowS
showList :: [Sum a] -> ShowS
Show     -- ^ @since 2.01
                 , Sum a
Sum a -> Sum a -> Bounded (Sum a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Sum a
$cminBound :: forall a. Bounded a => Sum a
minBound :: Sum a
$cmaxBound :: forall a. Bounded a => Sum a
maxBound :: Sum a
Bounded  -- ^ @since 2.01
                 , (forall x. Sum a -> Rep (Sum a) x)
-> (forall x. Rep (Sum a) x -> Sum a) -> Generic (Sum a)
forall x. Rep (Sum a) x -> Sum a
forall x. Sum a -> Rep (Sum a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Sum a) x -> Sum a
forall a x. Sum a -> Rep (Sum a) x
$cfrom :: forall a x. Sum a -> Rep (Sum a) x
from :: forall x. Sum a -> Rep (Sum a) x
$cto :: forall a x. Rep (Sum a) x -> Sum a
to :: forall x. Rep (Sum a) x -> Sum a
Generic  -- ^ @since 4.7.0.0
                 , (forall a. Sum a -> Rep1 Sum a)
-> (forall a. Rep1 Sum a -> Sum a) -> Generic1 Sum
forall a. Rep1 Sum a -> Sum a
forall a. Sum a -> Rep1 Sum a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. Sum a -> Rep1 Sum a
from1 :: forall a. Sum a -> Rep1 Sum a
$cto1 :: forall a. Rep1 Sum a -> Sum a
to1 :: forall a. Rep1 Sum a -> Sum a
Generic1 -- ^ @since 4.7.0.0
                 , Integer -> Sum a
Sum a -> Sum a
Sum a -> Sum a -> Sum a
(Sum a -> Sum a -> Sum a)
-> (Sum a -> Sum a -> Sum a)
-> (Sum a -> Sum a -> Sum a)
-> (Sum a -> Sum a)
-> (Sum a -> Sum a)
-> (Sum a -> Sum a)
-> (Integer -> Sum a)
-> Num (Sum a)
forall a. Num a => Integer -> Sum a
forall a. Num a => Sum a -> Sum a
forall a. Num a => Sum a -> Sum a -> Sum a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => Sum a -> Sum a -> Sum a
+ :: Sum a -> Sum a -> Sum a
$c- :: forall a. Num a => Sum a -> Sum a -> Sum a
- :: Sum a -> Sum a -> Sum a
$c* :: forall a. Num a => Sum a -> Sum a -> Sum a
* :: Sum a -> Sum a -> Sum a
$cnegate :: forall a. Num a => Sum a -> Sum a
negate :: Sum a -> Sum a
$cabs :: forall a. Num a => Sum a -> Sum a
abs :: Sum a -> Sum a
$csignum :: forall a. Num a => Sum a -> Sum a
signum :: Sum a -> Sum a
$cfromInteger :: forall a. Num a => Integer -> Sum a
fromInteger :: Integer -> Sum a
Num      -- ^ @since 4.7.0.0
                 )

-- | @since 4.9.0.0
instance Num a => Semigroup (Sum a) where
        <> :: Sum a -> Sum a -> Sum a
(<>) = (a -> a -> a) -> Sum a -> Sum a -> Sum a
forall a b. Coercible a b => a -> b
coerce (a -> a -> a
forall a. Num a => a -> a -> a
(+) :: a -> a -> a)
        stimes :: forall b. Integral b => b -> Sum a -> Sum a
stimes b
n (Sum a
a) = a -> Sum a
forall a. a -> Sum a
Sum (b -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral b
n a -> a -> a
forall a. Num a => a -> a -> a
* a
a)

-- | @since 2.01
instance Num a => Monoid (Sum a) where
        mempty :: Sum a
mempty = a -> Sum a
forall a. a -> Sum a
Sum a
0
        -- By default, we would get a lazy right fold. This forces the use of a strict
        -- left fold instead.
        mconcat :: [Sum a] -> Sum a
mconcat = (Sum a -> Sum a -> Sum a) -> Sum a -> [Sum a] -> Sum a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' Sum a -> Sum a -> Sum a
forall a. Semigroup a => a -> a -> a
(<>) Sum a
forall a. Monoid a => a
mempty
        {-# INLINE mconcat #-}

-- | @since 4.8.0.0
instance Functor Sum where
    fmap :: forall a b. (a -> b) -> Sum a -> Sum b
fmap     = (a -> b) -> Sum a -> Sum b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Applicative Sum where
    pure :: forall a. a -> Sum a
pure     = a -> Sum a
forall a. a -> Sum a
Sum
    <*> :: forall a b. Sum (a -> b) -> Sum a -> Sum b
(<*>)    = Sum (a -> b) -> Sum a -> Sum b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Monad Sum where
    Sum a
m >>= :: forall a b. Sum a -> (a -> Sum b) -> Sum b
>>= a -> Sum b
k  = a -> Sum b
k (Sum a -> a
forall a. Sum a -> a
getSum Sum a
m)

-- | Monoid under multiplication.
--
-- >>> getProduct (Product 3 <> Product 4 <> mempty)
-- 12
newtype Product a = Product { forall a. Product a -> a
getProduct :: a }
        deriving ( Product a -> Product a -> Bool
(Product a -> Product a -> Bool)
-> (Product a -> Product a -> Bool) -> Eq (Product a)
forall a. Eq a => Product a -> Product a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Product a -> Product a -> Bool
== :: Product a -> Product a -> Bool
$c/= :: forall a. Eq a => Product a -> Product a -> Bool
/= :: Product a -> Product a -> Bool
Eq       -- ^ @since 2.01
                 , Eq (Product a)
Eq (Product a)
-> (Product a -> Product a -> Ordering)
-> (Product a -> Product a -> Bool)
-> (Product a -> Product a -> Bool)
-> (Product a -> Product a -> Bool)
-> (Product a -> Product a -> Bool)
-> (Product a -> Product a -> Product a)
-> (Product a -> Product a -> Product a)
-> Ord (Product a)
Product a -> Product a -> Bool
Product a -> Product a -> Ordering
Product a -> Product a -> Product a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (Product a)
forall a. Ord a => Product a -> Product a -> Bool
forall a. Ord a => Product a -> Product a -> Ordering
forall a. Ord a => Product a -> Product a -> Product a
$ccompare :: forall a. Ord a => Product a -> Product a -> Ordering
compare :: Product a -> Product a -> Ordering
$c< :: forall a. Ord a => Product a -> Product a -> Bool
< :: Product a -> Product a -> Bool
$c<= :: forall a. Ord a => Product a -> Product a -> Bool
<= :: Product a -> Product a -> Bool
$c> :: forall a. Ord a => Product a -> Product a -> Bool
> :: Product a -> Product a -> Bool
$c>= :: forall a. Ord a => Product a -> Product a -> Bool
>= :: Product a -> Product a -> Bool
$cmax :: forall a. Ord a => Product a -> Product a -> Product a
max :: Product a -> Product a -> Product a
$cmin :: forall a. Ord a => Product a -> Product a -> Product a
min :: Product a -> Product a -> Product a
Ord      -- ^ @since 2.01
                 , ReadPrec [Product a]
ReadPrec (Product a)
Int -> ReadS (Product a)
ReadS [Product a]
(Int -> ReadS (Product a))
-> ReadS [Product a]
-> ReadPrec (Product a)
-> ReadPrec [Product a]
-> Read (Product a)
forall a. Read a => ReadPrec [Product a]
forall a. Read a => ReadPrec (Product a)
forall a. Read a => Int -> ReadS (Product a)
forall a. Read a => ReadS [Product a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Product a)
readsPrec :: Int -> ReadS (Product a)
$creadList :: forall a. Read a => ReadS [Product a]
readList :: ReadS [Product a]
$creadPrec :: forall a. Read a => ReadPrec (Product a)
readPrec :: ReadPrec (Product a)
$creadListPrec :: forall a. Read a => ReadPrec [Product a]
readListPrec :: ReadPrec [Product a]
Read     -- ^ @since 2.01
                 , Int -> Product a -> ShowS
[Product a] -> ShowS
Product a -> [Char]
(Int -> Product a -> ShowS)
-> (Product a -> [Char])
-> ([Product a] -> ShowS)
-> Show (Product a)
forall a. Show a => Int -> Product a -> ShowS
forall a. Show a => [Product a] -> ShowS
forall a. Show a => Product a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Product a -> ShowS
showsPrec :: Int -> Product a -> ShowS
$cshow :: forall a. Show a => Product a -> [Char]
show :: Product a -> [Char]
$cshowList :: forall a. Show a => [Product a] -> ShowS
showList :: [Product a] -> ShowS
Show     -- ^ @since 2.01
                 , Product a
Product a -> Product a -> Bounded (Product a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Product a
$cminBound :: forall a. Bounded a => Product a
minBound :: Product a
$cmaxBound :: forall a. Bounded a => Product a
maxBound :: Product a
Bounded  -- ^ @since 2.01
                 , (forall x. Product a -> Rep (Product a) x)
-> (forall x. Rep (Product a) x -> Product a)
-> Generic (Product a)
forall x. Rep (Product a) x -> Product a
forall x. Product a -> Rep (Product a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Product a) x -> Product a
forall a x. Product a -> Rep (Product a) x
$cfrom :: forall a x. Product a -> Rep (Product a) x
from :: forall x. Product a -> Rep (Product a) x
$cto :: forall a x. Rep (Product a) x -> Product a
to :: forall x. Rep (Product a) x -> Product a
Generic  -- ^ @since 4.7.0.0
                 , (forall a. Product a -> Rep1 Product a)
-> (forall a. Rep1 Product a -> Product a) -> Generic1 Product
forall a. Rep1 Product a -> Product a
forall a. Product a -> Rep1 Product a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
$cfrom1 :: forall a. Product a -> Rep1 Product a
from1 :: forall a. Product a -> Rep1 Product a
$cto1 :: forall a. Rep1 Product a -> Product a
to1 :: forall a. Rep1 Product a -> Product a
Generic1 -- ^ @since 4.7.0.0
                 , Integer -> Product a
Product a -> Product a
Product a -> Product a -> Product a
(Product a -> Product a -> Product a)
-> (Product a -> Product a -> Product a)
-> (Product a -> Product a -> Product a)
-> (Product a -> Product a)
-> (Product a -> Product a)
-> (Product a -> Product a)
-> (Integer -> Product a)
-> Num (Product a)
forall a. Num a => Integer -> Product a
forall a. Num a => Product a -> Product a
forall a. Num a => Product a -> Product a -> Product a
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: forall a. Num a => Product a -> Product a -> Product a
+ :: Product a -> Product a -> Product a
$c- :: forall a. Num a => Product a -> Product a -> Product a
- :: Product a -> Product a -> Product a
$c* :: forall a. Num a => Product a -> Product a -> Product a
* :: Product a -> Product a -> Product a
$cnegate :: forall a. Num a => Product a -> Product a
negate :: Product a -> Product a
$cabs :: forall a. Num a => Product a -> Product a
abs :: Product a -> Product a
$csignum :: forall a. Num a => Product a -> Product a
signum :: Product a -> Product a
$cfromInteger :: forall a. Num a => Integer -> Product a
fromInteger :: Integer -> Product a
Num      -- ^ @since 4.7.0.0
                 )

-- | @since 4.9.0.0
instance Num a => Semigroup (Product a) where
        <> :: Product a -> Product a -> Product a
(<>) = (a -> a -> a) -> Product a -> Product a -> Product a
forall a b. Coercible a b => a -> b
coerce (a -> a -> a
forall a. Num a => a -> a -> a
(*) :: a -> a -> a)
        stimes :: forall b. Integral b => b -> Product a -> Product a
stimes b
n (Product a
a) = a -> Product a
forall a. a -> Product a
Product (a
a a -> b -> a
forall a b. (Num a, Integral b) => a -> b -> a
^ b
n)


-- | @since 2.01
instance Num a => Monoid (Product a) where
        mempty :: Product a
mempty = a -> Product a
forall a. a -> Product a
Product a
1
        -- By default, we would get a lazy right fold. This forces the use of a strict
        -- left fold instead.
        mconcat :: [Product a] -> Product a
mconcat = (Product a -> Product a -> Product a)
-> Product a -> [Product a] -> Product a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' Product a -> Product a -> Product a
forall a. Semigroup a => a -> a -> a
(<>) Product a
forall a. Monoid a => a
mempty
        {-# INLINE mconcat #-}

-- | @since 4.8.0.0
instance Functor Product where
    fmap :: forall a b. (a -> b) -> Product a -> Product b
fmap     = (a -> b) -> Product a -> Product b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Applicative Product where
    pure :: forall a. a -> Product a
pure     = a -> Product a
forall a. a -> Product a
Product
    <*> :: forall a b. Product (a -> b) -> Product a -> Product b
(<*>)    = Product (a -> b) -> Product a -> Product b
forall a b. Coercible a b => a -> b
coerce

-- | @since 4.8.0.0
instance Monad Product where
    Product a
m >>= :: forall a b. Product a -> (a -> Product b) -> Product b
>>= a -> Product b
k  = a -> Product b
k (Product a -> a
forall a. Product a -> a
getProduct Product a
m)


-- | Monoid under '<|>'.
--
-- >>> getAlt (Alt (Just 12) <> Alt (Just 24))
-- Just 12
--
-- >>> getAlt $ Alt Nothing <> Alt (Just 24)
-- Just 24
--
-- @since 4.8.0.0
newtype Alt f a = Alt {forall {k} (f :: k -> *) (a :: k). Alt f a -> f a
getAlt :: f a}
  deriving ( (forall x. Alt f a -> Rep (Alt f a) x)
-> (forall x. Rep (Alt f a) x -> Alt f a) -> Generic (Alt f a)
forall x. Rep (Alt f a) x -> Alt f a
forall x. Alt f a -> Rep (Alt f a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (f :: k -> *) (a :: k) x. Rep (Alt f a) x -> Alt f a
forall k (f :: k -> *) (a :: k) x. Alt f a -> Rep (Alt f a) x
$cfrom :: forall k (f :: k -> *) (a :: k) x. Alt f a -> Rep (Alt f a) x
from :: forall x. Alt f a -> Rep (Alt f a) x
$cto :: forall k (f :: k -> *) (a :: k) x. Rep (Alt f a) x -> Alt f a
to :: forall x. Rep (Alt f a) x -> Alt f a
Generic     -- ^ @since 4.8.0.0
           , (forall (a :: k). Alt f a -> Rep1 (Alt f) a)
-> (forall (a :: k). Rep1 (Alt f) a -> Alt f a) -> Generic1 (Alt f)
forall (a :: k). Rep1 (Alt f) a -> Alt f a
forall (a :: k). Alt f a -> Rep1 (Alt f) a
forall k (f :: k -> *).
(forall (a :: k). f a -> Rep1 f a)
-> (forall (a :: k). Rep1 f a -> f a) -> Generic1 f
forall k (f :: k -> *) (a :: k). Rep1 (Alt f) a -> Alt f a
forall k (f :: k -> *) (a :: k). Alt f a -> Rep1 (Alt f) a
$cfrom1 :: forall k (f :: k -> *) (a :: k). Alt f a -> Rep1 (Alt f) a
from1 :: forall (a :: k). Alt f a -> Rep1 (Alt f) a
$cto1 :: forall k (f :: k -> *) (a :: k). Rep1 (Alt f) a -> Alt f a
to1 :: forall (a :: k). Rep1 (Alt f) a -> Alt f a
Generic1    -- ^ @since 4.8.0.0
           , ReadPrec [Alt f a]
ReadPrec (Alt f a)
Int -> ReadS (Alt f a)
ReadS [Alt f a]
(Int -> ReadS (Alt f a))
-> ReadS [Alt f a]
-> ReadPrec (Alt f a)
-> ReadPrec [Alt f a]
-> Read (Alt f a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (f :: k -> *) (a :: k). Read (f a) => ReadPrec [Alt f a]
forall k (f :: k -> *) (a :: k). Read (f a) => ReadPrec (Alt f a)
forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (Alt f a)
forall k (f :: k -> *) (a :: k). Read (f a) => ReadS [Alt f a]
$creadsPrec :: forall k (f :: k -> *) (a :: k).
Read (f a) =>
Int -> ReadS (Alt f a)
readsPrec :: Int -> ReadS (Alt f a)
$creadList :: forall k (f :: k -> *) (a :: k). Read (f a) => ReadS [Alt f a]
readList :: ReadS [Alt f a]
$creadPrec :: forall k (f :: k -> *) (a :: k). Read (f a) => ReadPrec (Alt f a)
readPrec :: ReadPrec (Alt f a)
$creadListPrec :: forall k (f :: k -> *) (a :: k). Read (f a) => ReadPrec [Alt f a]
readListPrec :: ReadPrec [Alt f a]
Read        -- ^ @since 4.8.0.0
           , Int -> Alt f a -> ShowS
[Alt f a] -> ShowS
Alt f a -> [Char]
(Int -> Alt f a -> ShowS)
-> (Alt f a -> [Char]) -> ([Alt f a] -> ShowS) -> Show (Alt f a)
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> Alt f a -> ShowS
forall k (f :: k -> *) (a :: k). Show (f a) => [Alt f a] -> ShowS
forall k (f :: k -> *) (a :: k). Show (f a) => Alt f a -> [Char]
$cshowsPrec :: forall k (f :: k -> *) (a :: k).
Show (f a) =>
Int -> Alt f a -> ShowS
showsPrec :: Int -> Alt f a -> ShowS
$cshow :: forall k (f :: k -> *) (a :: k). Show (f a) => Alt f a -> [Char]
show :: Alt f a -> [Char]
$cshowList :: forall k (f :: k -> *) (a :: k). Show (f a) => [Alt f a] -> ShowS
showList :: [Alt f a] -> ShowS
Show        -- ^ @since 4.8.0.0
           , Alt f a -> Alt f a -> Bool
(Alt f a -> Alt f a -> Bool)
-> (Alt f a -> Alt f a -> Bool) -> Eq (Alt f a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (f :: k -> *) (a :: k).
Eq (f a) =>
Alt f a -> Alt f a -> Bool
$c== :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
Alt f a -> Alt f a -> Bool
== :: Alt f a -> Alt f a -> Bool
$c/= :: forall k (f :: k -> *) (a :: k).
Eq (f a) =>
Alt f a -> Alt f a -> Bool
/= :: Alt f a -> Alt f a -> Bool
Eq          -- ^ @since 4.8.0.0
           , Eq (Alt f a)
Eq (Alt f a)
-> (Alt f a -> Alt f a -> Ordering)
-> (Alt f a -> Alt f a -> Bool)
-> (Alt f a -> Alt f a -> Bool)
-> (Alt f a -> Alt f a -> Bool)
-> (Alt f a -> Alt f a -> Bool)
-> (Alt f a -> Alt f a -> Alt f a)
-> (Alt f a -> Alt f a -> Alt f a)
-> Ord (Alt f a)
Alt f a -> Alt f a -> Bool
Alt f a -> Alt f a -> Ordering
Alt f a -> Alt f a -> Alt f a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {f :: k -> *} {a :: k}. Ord (f a) => Eq (Alt f a)
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Bool
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Ordering
forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Alt f a
$ccompare :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Ordering
compare :: Alt f a -> Alt f a -> Ordering
$c< :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Bool
< :: Alt f a -> Alt f a -> Bool
$c<= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Bool
<= :: Alt f a -> Alt f a -> Bool
$c> :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Bool
> :: Alt f a -> Alt f a -> Bool
$c>= :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Bool
>= :: Alt f a -> Alt f a -> Bool
$cmax :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Alt f a
max :: Alt f a -> Alt f a -> Alt f a
$cmin :: forall k (f :: k -> *) (a :: k).
Ord (f a) =>
Alt f a -> Alt f a -> Alt f a
min :: Alt f a -> Alt f a -> Alt f a
Ord         -- ^ @since 4.8.0.0
           , Integer -> Alt f a
Alt f a -> Alt f a
Alt f a -> Alt f a -> Alt f a
(Alt f a -> Alt f a -> Alt f a)
-> (Alt f a -> Alt f a -> Alt f a)
-> (Alt f a -> Alt f a -> Alt f a)
-> (Alt f a -> Alt f a)
-> (Alt f a -> Alt f a)
-> (Alt f a -> Alt f a)
-> (Integer -> Alt f a)
-> Num (Alt f a)
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
forall k (f :: k -> *) (a :: k). Num (f a) => Integer -> Alt f a
forall k (f :: k -> *) (a :: k). Num (f a) => Alt f a -> Alt f a
forall k (f :: k -> *) (a :: k).
Num (f a) =>
Alt f a -> Alt f a -> Alt f a
$c+ :: forall k (f :: k -> *) (a :: k).
Num (f a) =>
Alt f a -> Alt f a -> Alt f a
+ :: Alt f a -> Alt f a -> Alt f a
$c- :: forall k (f :: k -> *) (a :: k).
Num (f a) =>
Alt f a -> Alt f a -> Alt f a
- :: Alt f a -> Alt f a -> Alt f a
$c* :: forall k (f :: k -> *) (a :: k).
Num (f a) =>
Alt f a -> Alt f a -> Alt f a
* :: Alt f a -> Alt f a -> Alt f a
$cnegate :: forall k (f :: k -> *) (a :: k). Num (f a) => Alt f a -> Alt f a
negate :: Alt f a -> Alt f a
$cabs :: forall k (f :: k -> *) (a :: k). Num (f a) => Alt f a -> Alt f a
abs :: Alt f a -> Alt f a
$csignum :: forall k (f :: k -> *) (a :: k). Num (f a) => Alt f a -> Alt f a
signum :: Alt f a -> Alt f a
$cfromInteger :: forall k (f :: k -> *) (a :: k). Num (f a) => Integer -> Alt f a
fromInteger :: Integer -> Alt f a
Num         -- ^ @since 4.8.0.0
           , Int -> Alt f a
Alt f a -> Int
Alt f a -> [Alt f a]
Alt f a -> Alt f a
Alt f a -> Alt f a -> [Alt f a]
Alt f a -> Alt f a -> Alt f a -> [Alt f a]
(Alt f a -> Alt f a)
-> (Alt f a -> Alt f a)
-> (Int -> Alt f a)
-> (Alt f a -> Int)
-> (Alt f a -> [Alt f a])
-> (Alt f a -> Alt f a -> [Alt f a])
-> (Alt f a -> Alt f a -> [Alt f a])
-> (Alt f a -> Alt f a -> Alt f a -> [Alt f a])
-> Enum (Alt f a)
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
forall k (f :: k -> *) (a :: k). Enum (f a) => Int -> Alt f a
forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> Int
forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> [Alt f a]
forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> Alt f a
forall k (f :: k -> *) (a :: k).
Enum (f a) =>
Alt f a -> Alt f a -> [Alt f a]
forall k (f :: k -> *) (a :: k).
Enum (f a) =>
Alt f a -> Alt f a -> Alt f a -> [Alt f a]
$csucc :: forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> Alt f a
succ :: Alt f a -> Alt f a
$cpred :: forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> Alt f a
pred :: Alt f a -> Alt f a
$ctoEnum :: forall k (f :: k -> *) (a :: k). Enum (f a) => Int -> Alt f a
toEnum :: Int -> Alt f a
$cfromEnum :: forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> Int
fromEnum :: Alt f a -> Int
$cenumFrom :: forall k (f :: k -> *) (a :: k). Enum (f a) => Alt f a -> [Alt f a]
enumFrom :: Alt f a -> [Alt f a]
$cenumFromThen :: forall k (f :: k -> *) (a :: k).
Enum (f a) =>
Alt f a -> Alt f a -> [Alt f a]
enumFromThen :: Alt f a -> Alt f a -> [Alt f a]
$cenumFromTo :: forall k (f :: k -> *) (a :: k).
Enum (f a) =>
Alt f a -> Alt f a -> [Alt f a]
enumFromTo :: Alt f a -> Alt f a -> [Alt f a]
$cenumFromThenTo :: forall k (f :: k -> *) (a :: k).
Enum (f a) =>
Alt f a -> Alt f a -> Alt f a -> [Alt f a]
enumFromThenTo :: Alt f a -> Alt f a -> Alt f a -> [Alt f a]
Enum        -- ^ @since 4.8.0.0
           , Applicative (Alt f)
Applicative (Alt f)
-> (forall a b. Alt f a -> (a -> Alt f b) -> Alt f b)
-> (forall a b. Alt f a -> Alt f b -> Alt f b)
-> (forall a. a -> Alt f a)
-> Monad (Alt f)
forall a. a -> Alt f a
forall a b. Alt f a -> Alt f b -> Alt f b
forall a b. Alt f a -> (a -> Alt f b) -> Alt f b
forall {f :: * -> *}. Monad f => Applicative (Alt f)
forall (f :: * -> *) a. Monad f => a -> Alt f a
forall (f :: * -> *) a b. Monad f => Alt f a -> Alt f b -> Alt f b
forall (f :: * -> *) a b.
Monad f =>
Alt f a -> (a -> Alt f b) -> Alt f b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall (f :: * -> *) a b.
Monad f =>
Alt f a -> (a -> Alt f b) -> Alt f b
>>= :: forall a b. Alt f a -> (a -> Alt f b) -> Alt f b
$c>> :: forall (f :: * -> *) a b. Monad f => Alt f a -> Alt f b -> Alt f b
>> :: forall a b. Alt f a -> Alt f b -> Alt f b
$creturn :: forall (f :: * -> *) a. Monad f => a -> Alt f a
return :: forall a. a -> Alt f a
Monad       -- ^ @since 4.8.0.0
           , Monad (Alt f)
Alternative (Alt f)
Alternative (Alt f)
-> Monad (Alt f)
-> (forall a. Alt f a)
-> (forall a. Alt f a -> Alt f a -> Alt f a)
-> MonadPlus (Alt f)
forall a. Alt f a
forall a. Alt f a -> Alt f a -> Alt f a
forall {f :: * -> *}. MonadPlus f => Monad (Alt f)
forall {f :: * -> *}. MonadPlus f => Alternative (Alt f)
forall (f :: * -> *) a. MonadPlus f => Alt f a
forall (f :: * -> *) a.
MonadPlus f =>
Alt f a -> Alt f a -> Alt f a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
$cmzero :: forall (f :: * -> *) a. MonadPlus f => Alt f a
mzero :: forall a. Alt f a
$cmplus :: forall (f :: * -> *) a.
MonadPlus f =>
Alt f a -> Alt f a -> Alt f a
mplus :: forall a. Alt f a -> Alt f a -> Alt f a
MonadPlus   -- ^ @since 4.8.0.0
           , Functor (Alt f)
Functor (Alt f)
-> (forall a. a -> Alt f a)
-> (forall a b. Alt f (a -> b) -> Alt f a -> Alt f b)
-> (forall a b c. (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c)
-> (forall a b. Alt f a -> Alt f b -> Alt f b)
-> (forall a b. Alt f a -> Alt f b -> Alt f a)
-> Applicative (Alt f)
forall a. a -> Alt f a
forall a b. Alt f a -> Alt f b -> Alt f a
forall a b. Alt f a -> Alt f b -> Alt f b
forall a b. Alt f (a -> b) -> Alt f a -> Alt f b
forall a b c. (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {f :: * -> *}. Applicative f => Functor (Alt f)
forall (f :: * -> *) a. Applicative f => a -> Alt f a
forall (f :: * -> *) a b.
Applicative f =>
Alt f a -> Alt f b -> Alt f a
forall (f :: * -> *) a b.
Applicative f =>
Alt f a -> Alt f b -> Alt f b
forall (f :: * -> *) a b.
Applicative f =>
Alt f (a -> b) -> Alt f a -> Alt f b
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> Alt f a -> Alt f b -> Alt f c
$cpure :: forall (f :: * -> *) a. Applicative f => a -> Alt f a
pure :: forall a. a -> Alt f a
$c<*> :: forall (f :: * -> *) a b.
Applicative f =>
Alt f (a -> b) -> Alt f a -> Alt f b
<*> :: forall a b. Alt f (a -> b) -> Alt f a -> Alt f b
$cliftA2 :: forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> Alt f a -> Alt f b -> Alt f c
liftA2 :: forall a b c. (a -> b -> c) -> Alt f a -> Alt f b -> Alt f c
$c*> :: forall (f :: * -> *) a b.
Applicative f =>
Alt f a -> Alt f b -> Alt f b
*> :: forall a b. Alt f a -> Alt f b -> Alt f b
$c<* :: forall (f :: * -> *) a b.
Applicative f =>
Alt f a -> Alt f b -> Alt f a
<* :: forall a b. Alt f a -> Alt f b -> Alt f a
Applicative -- ^ @since 4.8.0.0
           , Applicative (Alt f)
Applicative (Alt f)
-> (forall a. Alt f a)
-> (forall a. Alt f a -> Alt f a -> Alt f a)
-> (forall a. Alt f a -> Alt f [a])
-> (forall a. Alt f a -> Alt f [a])
-> Alternative (Alt f)
forall a. Alt f a
forall a. Alt f a -> Alt f [a]
forall a. Alt f a -> Alt f a -> Alt f a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall {f :: * -> *}. Alternative f => Applicative (Alt f)
forall (f :: * -> *) a. Alternative f => Alt f a
forall (f :: * -> *) a. Alternative f => Alt f a -> Alt f [a]
forall (f :: * -> *) a.
Alternative f =>
Alt f a -> Alt f a -> Alt f a
$cempty :: forall (f :: * -> *) a. Alternative f => Alt f a
empty :: forall a. Alt f a
$c<|> :: forall (f :: * -> *) a.
Alternative f =>
Alt f a -> Alt f a -> Alt f a
<|> :: forall a. Alt f a -> Alt f a -> Alt f a
$csome :: forall (f :: * -> *) a. Alternative f => Alt f a -> Alt f [a]
some :: forall a. Alt f a -> Alt f [a]
$cmany :: forall (f :: * -> *) a. Alternative f => Alt f a -> Alt f [a]
many :: forall a. Alt f a -> Alt f [a]
Alternative -- ^ @since 4.8.0.0
           , (forall a b. (a -> b) -> Alt f a -> Alt f b)
-> (forall a b. a -> Alt f b -> Alt f a) -> Functor (Alt f)
forall a b. a -> Alt f b -> Alt f a
forall a b. (a -> b) -> Alt f a -> Alt f b
forall (f :: * -> *) a b. Functor f => a -> Alt f b -> Alt f a
forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> Alt f a -> Alt f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (f :: * -> *) a b.
Functor f =>
(a -> b) -> Alt f a -> Alt f b
fmap :: forall a b. (a -> b) -> Alt f a -> Alt f b
$c<$ :: forall (f :: * -> *) a b. Functor f => a -> Alt f b -> Alt f a
<$ :: forall a b. a -> Alt f b -> Alt f a
Functor     -- ^ @since 4.8.0.0
           )

-- | @since 4.9.0.0
instance Alternative f => Semigroup (Alt f a) where
    <> :: Alt f a -> Alt f a -> Alt f a
(<>) = (f a -> f a -> f a) -> Alt f a -> Alt f a -> Alt f a
forall a b. Coercible a b => a -> b
coerce (f a -> f a -> f a
forall a. f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) :: f a -> f a -> f a)
    stimes :: forall b. Integral b => b -> Alt f a -> Alt f a
stimes = b -> Alt f a -> Alt f a
forall b a. (Integral b, Monoid a) => b -> a -> a
stimesMonoid

-- | @since 4.8.0.0
instance Alternative f => Monoid (Alt f a) where
    mempty :: Alt f a
mempty = f a -> Alt f a
forall {k} (f :: k -> *) (a :: k). f a -> Alt f a
Alt f a
forall a. f a
forall (f :: * -> *) a. Alternative f => f a
empty