-- vim:fdm=marker:foldtext=foldtext()

--------------------------------------------------------------------
-- |
-- Module    : Test.SmallCheck.Series
-- Copyright : (c) Colin Runciman et al.
-- License   : BSD3
-- Maintainer: Roman Cheplyaka <roma@ro-che.info>
--
-- You need this module if you want to generate test values of your own
-- types.
--
-- You'll typically need the following extensions:
--
-- >{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
--
-- SmallCheck itself defines data generators for all the data types used
-- by the "Prelude".
--
-- In order to generate values and functions of your own types, you need
-- to make them instances of 'Serial' (for values) and 'CoSerial' (for
-- functions). There are two main ways to do so: using Generics or writing
-- the instances by hand.
--------------------------------------------------------------------

{-# LANGUAGE CPP                   #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE DefaultSignatures     #-}
#endif
{-# LANGUAGE DeriveFoldable        #-}
{-# LANGUAGE DeriveFunctor         #-}
{-# LANGUAGE DeriveTraversable     #-}
{-# LANGUAGE FlexibleContexts      #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude     #-}
{-# LANGUAGE RankNTypes            #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE TypeOperators         #-}

#if MIN_VERSION_base(4,8,0)
{-# LANGUAGE Safe                  #-}
#else
{-# LANGUAGE OverlappingInstances  #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Trustworthy           #-}
#endif
#endif

#define HASCBOOL MIN_VERSION_base(4,10,0)

module Test.SmallCheck.Series (
  -- {{{
  -- * Generic instances
  -- | The easiest way to create the necessary instances is to use GHC
  -- generics (available starting with GHC 7.2.1).
  --
  -- Here's a complete example:
  --
  -- >{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
  -- >{-# LANGUAGE DeriveGeneric #-}
  -- >
  -- >import Test.SmallCheck.Series
  -- >import GHC.Generics
  -- >
  -- >data Tree a = Null | Fork (Tree a) a (Tree a)
  -- >    deriving Generic
  -- >
  -- >instance Serial m a => Serial m (Tree a)
  --
  -- Here we enable the @DeriveGeneric@ extension which allows to derive 'Generic'
  -- instance for our data type. Then we declare that @Tree@ @a@ is an instance of
  -- 'Serial', but do not provide any definitions. This causes GHC to use the
  -- default definitions that use the 'Generic' instance.
  --
  -- One minor limitation of generic instances is that there's currently no
  -- way to distinguish newtypes and datatypes. Thus, newtype constructors
  -- will also count as one level of depth.

  -- * Data Generators
  -- | Writing 'Serial' instances for application-specific types is
  -- straightforward. You need to define a 'series' generator, typically using
  -- @consN@ family of generic combinators where N is constructor arity.
  --
  -- For example:
  --
  -- >data Tree a = Null | Fork (Tree a) a (Tree a)
  -- >
  -- >instance Serial m a => Serial m (Tree a) where
  -- >  series = cons0 Null \/ cons3 Fork
  --
  -- For newtypes use 'newtypeCons' instead of 'cons1'.
  -- The difference is that 'cons1' is counts as one level of depth, while
  -- 'newtypeCons' doesn't affect the depth.
  --
  -- >newtype Light a = Light a
  -- >
  -- >instance Serial m a => Serial m (Light a) where
  -- >  series = newtypeCons Light
  --
  -- For data types with more than 6 fields define @consN@ as
  --
  -- >consN f = decDepth $
  -- >  f <$> series
  -- >    <~> series
  -- >    <~> series
  -- >    <~> ...    {- series repeated N times in total -}

  -- ** What does @consN@ do, exactly?

  -- | @consN@ has type
  -- @(Serial t₁, ..., Serial tₙ) => (t₁ -> ... -> tₙ -> t) -> Series t@.
  --
  -- @consN@ @f@ is a series which, for a given depth \(d > 0\), produces values of the
  -- form
  --
  -- >f x₁ ... xₙ
  --
  -- where @xₖ@ ranges over all values of type @tₖ@ of depth up to \(d-1\)
  -- (as defined by the 'series' functions for @tₖ@).
  --
  -- @consN@ functions also ensure that xₖ are enumerated in the
  -- breadth-first order. Thus, combinations of smaller depth come first
  -- (assuming the same is true for @tₖ@).
  --
  -- If \(d \le 0\), no values are produced.

  cons0, cons1, cons2, cons3, cons4, cons5, cons6, newtypeCons,
  -- * Function Generators

  -- | To generate functions of an application-specific argument type,
  -- make the type an instance of 'CoSerial'.
  --
  -- Again there is a standard pattern, this time using the @altsN@
  -- combinators where again N is constructor arity.  Here are @Tree@ and
  -- @Light@ instances:
  --
  --
  -- >instance CoSerial m a => CoSerial m (Tree a) where
  -- >  coseries rs =
  -- >    alts0 rs >>- \z ->
  -- >    alts3 rs >>- \f ->
  -- >    return $ \t ->
  -- >      case t of
  -- >        Null -> z
  -- >        Fork t1 x t2 -> f t1 x t2
  --
  -- >instance CoSerial m a => CoSerial m (Light a) where
  -- >  coseries rs =
  -- >    newtypeAlts rs >>- \f ->
  -- >    return $ \l ->
  -- >      case l of
  -- >        Light x -> f x
  --
  -- For data types with more than 6 fields define @altsN@ as
  --
  -- >altsN rs = do
  -- >  rs <- fixDepth rs
  -- >  decDepthChecked
  -- >    (constM $ constM $ ... $ constM rs)
  -- >    (coseries $ coseries $ ... $ coseries rs)
  -- >    {- constM and coseries are repeated N times each -}

  -- ** What does altsN do, exactly?

  -- | @altsN@ has type
  -- @(Serial t₁, ..., Serial tₙ) => Series t -> Series (t₁ -> ... -> tₙ -> t)@.
  --
  -- @altsN@ @s@ is a series which, for a given depth \( d \), produces functions of
  -- type
  --
  -- >t₁ -> ... -> tₙ -> t
  --
  -- If \( d \le 0 \), these are constant functions, one for each value produced
  -- by @s@.
  --
  -- If \( d > 0 \), these functions inspect each of their arguments up to the depth
  -- \( d-1 \) (as defined by the 'coseries' functions for the corresponding
  -- types) and return values produced by @s@. The depth to which the
  -- values are enumerated does not depend on the depth of inspection.

  alts0, alts1, alts2, alts3, alts4, alts5, alts6, newtypeAlts,

  -- * Basic definitions
  Depth, Series, Serial(..), CoSerial(..),

#if __GLASGOW_HASKELL__ >= 702
  -- * Generic implementations
  genericSeries,
  genericCoseries,
#endif

  -- * Convenient wrappers
  Positive(..), NonNegative(..), NonZero(..), NonEmpty(..),

  -- * Other useful definitions
  (\/), (><), (<~>), (>>-),
  localDepth,
  decDepth,
  getDepth,
  generate,
  limit,
  listSeries,
  list,
  listM,
  fixDepth,
  decDepthChecked,
  constM
  -- }}}
  ) where

import Control.Applicative (empty, pure, (<$>), (<|>))
import Control.Monad (Monad, liftM, guard, mzero, mplus, msum, return, (>>), (>>=))
import Control.Monad.Identity (Identity(Identity), runIdentity)
import Control.Monad.Logic (MonadLogic, (>>-), interleave, msplit, observeAllT)
import Control.Monad.Reader (ask, local)
import Data.Bool (Bool (True, False), (&&), (||))
import Data.Char (Char)
import Data.Complex (Complex((:+)))
import Data.Either (Either (Left, Right), either)
import Data.Eq (Eq, (==), (/=))
import Data.Foldable (Foldable)
import Data.Function (($), (.), const)
import Data.Functor (Functor, fmap)
import Data.Functor.Compose (Compose(Compose), getCompose)
import Data.Int (Int, Int8, Int16, Int32, Int64)
import Data.List (intercalate, take, map, length, (++), maximum, sum, unlines, lines, concat)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (Maybe (Just, Nothing), maybe)
import Data.Ord (Ord, Ordering (LT, EQ, GT), max, (<), (>), (>=), compare, (<=))
import Data.Ratio (Ratio, numerator, denominator, (%))
import Data.Traversable (Traversable)
import Data.Tuple (uncurry)
import Data.Void (Void, absurd)
import Data.Word (Word, Word8, Word16, Word32, Word64)
import Numeric.Natural (Natural)
import Prelude (Integer, Real, toRational, Enum, toEnum, fromEnum, Num, (+), (*), Integral, quotRem, toInteger, negate, abs, signum, fromInteger, Bounded, minBound, maxBound, Float, Double, (-), odd, encodeFloat, decodeFloat, realToFrac, seq, subtract)
import Test.SmallCheck.SeriesMonad
import Text.Show (Show, showsPrec, show)

#if MIN_VERSION_base(4,5,0)
import Foreign.C.Types (CFloat(CFloat), CDouble(CDouble), CChar(CChar), CSChar(CSChar), CUChar(CUChar), CShort(CShort), CUShort(CUShort), CInt(CInt), CUInt(CUInt), CLong(CLong), CULong(CULong), CPtrdiff(CPtrdiff), CSize(CSize), CWchar(CWchar), CSigAtomic(CSigAtomic), CLLong(CLLong), CULLong(CULLong), CIntPtr(CIntPtr), CUIntPtr(CUIntPtr), CIntMax(CIntMax), CUIntMax(CUIntMax), CClock(CClock), CTime(CTime), CUSeconds(CUSeconds), CSUSeconds(CSUSeconds))
#endif

#if __GLASGOW_HASKELL__ >= 702
import GHC.Generics (Generic, (:+:)(L1, R1), (:*:)((:*:)), C1, K1(K1), unK1, M1(M1), unM1, U1(U1), V1, Rep, to, from)
#else
import Prelude (RealFloat)
#endif
#if HASCBOOL
import Foreign.C.Types (CBool(CBool))
#endif

------------------------------
-- Main types and classes
------------------------------
--{{{

-- | @since 1.0
class Monad m => Serial m a where
  series   :: Series m a

#if __GLASGOW_HASKELL__ >= 704
  default series :: (Generic a, GSerial m (Rep a)) => Series m a
  series = forall (m :: * -> *) a.
(Monad m, Generic a, GSerial m (Rep a)) =>
Series m a
genericSeries
#endif

#if __GLASGOW_HASKELL__ >= 702
-- | @since 1.1.5
genericSeries
  :: (Monad m, Generic a, GSerial m (Rep a))
  => Series m a
genericSeries :: forall (m :: * -> *) a.
(Monad m, Generic a, GSerial m (Rep a)) =>
Series m a
genericSeries = forall a x. Generic a => Rep a x -> a
to forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries
#endif

-- | @since 1.0
class Monad m => CoSerial m a where
  -- | A proper 'coseries' implementation should pass the depth unchanged to
  -- its first argument. Doing otherwise will make enumeration of curried
  -- functions non-uniform in their arguments.
  coseries :: Series m b -> Series m (a->b)

#if __GLASGOW_HASKELL__ >= 704
  default coseries :: (Generic a, GCoSerial m (Rep a)) => Series m b -> Series m (a->b)
  coseries = forall (m :: * -> *) a b.
(Monad m, Generic a, GCoSerial m (Rep a)) =>
Series m b -> Series m (a -> b)
genericCoseries
#endif

#if __GLASGOW_HASKELL__ >= 702
-- | @since 1.1.5
genericCoseries
  :: (Monad m, Generic a, GCoSerial m (Rep a))
  => Series m b -> Series m (a->b)
genericCoseries :: forall (m :: * -> *) a b.
(Monad m, Generic a, GCoSerial m (Rep a)) =>
Series m b -> Series m (a -> b)
genericCoseries Series m b
rs = (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a x. Generic a => a -> Rep a x
from) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries Series m b
rs
#endif

-- }}}

------------------------------
-- Helper functions
------------------------------
-- {{{

-- | A simple series specified by a function from depth to the list of
-- values up to that depth.
--
-- @since 1.0
generate :: (Depth -> [a]) -> Series m a
generate :: forall a (m :: * -> *). (Depth -> [a]) -> Series m a
generate Depth -> [a]
f = do
  Depth
d <- forall (m :: * -> *). Series m Depth
getDepth
  forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Depth -> [a]
f Depth
d

-- | Limit a 'Series' to its first @n@ elements.
--
--  @since 1.1.5
limit :: forall m a . Monad m => Int -> Series m a -> Series m a
limit :: forall (m :: * -> *) a.
Monad m =>
Depth -> Series m a -> Series m a
limit Depth
n0 (Series ReaderT Depth (LogicT m) a
s) = forall (m :: * -> *) a. ReaderT Depth (LogicT m) a -> Series m a
Series forall a b. (a -> b) -> a -> b
$ forall {t} {ml :: * -> *} {b}.
(Eq t, Num t, MonadLogic ml) =>
t -> ml b -> ml b
go Depth
n0 ReaderT Depth (LogicT m) a
s
  where
    go :: t -> ml b -> ml b
go t
0 ml b
_ = forall (f :: * -> *) a. Alternative f => f a
empty
    go t
n ml b
mb1 = do
      Maybe (b, ml b)
cons :: Maybe (b, ml b) <- forall (m :: * -> *) a. MonadLogic m => m a -> m (Maybe (a, m a))
msplit ml b
mb1
      case Maybe (b, ml b)
cons of
        Maybe (b, ml b)
Nothing -> forall (f :: * -> *) a. Alternative f => f a
empty
        Just (b
b, ml b
mb2) -> forall (m :: * -> *) a. Monad m => a -> m a
return b
b forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> t -> ml b -> ml b
go (t
nforall a. Num a => a -> a -> a
-t
1) ml b
mb2

suchThat :: Series m a -> (a -> Bool) -> Series m a
suchThat :: forall (m :: * -> *) a. Series m a -> (a -> Bool) -> Series m a
suchThat Series m a
s a -> Bool
p = Series m a
s forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
x -> if a -> Bool
p a
x then forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x else forall (f :: * -> *) a. Alternative f => f a
empty

-- | Given a depth, return the list of values generated by a 'Serial' instance.
--
-- For example, list all integers up to depth 1:
--
-- * @listSeries 1 :: [Int]   -- returns [0,1,-1]@
--
-- @since 1.1.2
listSeries :: Serial Identity a => Depth -> [a]
listSeries :: forall a. Serial Identity a => Depth -> [a]
listSeries Depth
d = forall a. Depth -> Series Identity a -> [a]
list Depth
d forall (m :: * -> *) a. Serial m a => Series m a
series

-- | Return the list of values generated by a 'Series'. Useful for
-- debugging 'Serial' instances.
--
-- Examples:
--
-- * @'list' 3 'series' :: ['Int']                  -- returns [0,1,-1,2,-2,3,-3]@
--
-- * @'list' 3 ('series' :: 'Series' 'Data.Functor.Identity' 'Int')  -- returns [0,1,-1,2,-2,3,-3]@
--
-- * @'list' 2 'series' :: [['Bool']]               -- returns [[],['True'],['False']]@
--
-- The first two are equivalent. The second has a more explicit type binding.
--
-- @since 1.0
list :: Depth -> Series Identity a -> [a]
list :: forall a. Depth -> Series Identity a -> [a]
list Depth
d Series Identity a
s = forall a. Identity a -> a
runIdentity forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Applicative m => LogicT m a -> m [a]
observeAllT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Depth -> Series m a -> LogicT m a
runSeries Depth
d Series Identity a
s

-- | Monadic version of 'list'.
--
-- @since 1.1
listM :: Depth -> Series m a -> m [a]
listM Depth
d Series m a
s = forall (m :: * -> *) a. Applicative m => LogicT m a -> m [a]
observeAllT forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Depth -> Series m a -> LogicT m a
runSeries Depth
d Series m a
s

-- | Sum (union) of series.
--
-- @since 1.0
infixr 7 \/
(\/) :: Monad m => Series m a -> Series m a -> Series m a
\/ :: forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
(\/) = forall (m :: * -> *) a. MonadLogic m => m a -> m a -> m a
interleave

-- | Product of series
--
-- @since 1.0
infixr 8 ><
(><) :: Monad m => Series m a -> Series m b -> Series m (a,b)
Series m a
a >< :: forall (m :: * -> *) a b.
Monad m =>
Series m a -> Series m b -> Series m (a, b)
>< Series m b
b = (,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Series m a
a forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> Series m b
b

-- | Fair version of 'Control.Applicative.ap' and 'Control.Applicative.<*>'.
--
-- @since 1.0
infixl 4 <~>
(<~>) :: Monad m => Series m (a -> b) -> Series m a -> Series m b
Series m (a -> b)
a <~> :: forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> Series m a
b = Series m (a -> b)
a forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Series m a
b)

uncurry3 :: (a->b->c->d) -> ((a,b,c)->d)
uncurry3 :: forall a b c d. (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 a -> b -> c -> d
f (a
x,b
y,c
z) = a -> b -> c -> d
f a
x b
y c
z

uncurry4 :: (a->b->c->d->e) -> ((a,b,c,d)->e)
uncurry4 :: forall a b c d e. (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 a -> b -> c -> d -> e
f (a
w,b
x,c
y,d
z) = a -> b -> c -> d -> e
f a
w b
x c
y d
z

uncurry5 :: (a->b->c->d->e->f) -> ((a,b,c,d,e)->f)
uncurry5 :: forall a b c d e f.
(a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f
uncurry5 a -> b -> c -> d -> e -> f
f (a
v,b
w,c
x,d
y,e
z) = a -> b -> c -> d -> e -> f
f a
v b
w c
x d
y e
z

uncurry6 :: (a->b->c->d->e->f->g) -> ((a,b,c,d,e,f)->g)
uncurry6 :: forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g) -> (a, b, c, d, e, f) -> g
uncurry6 a -> b -> c -> d -> e -> f -> g
f (a
u,b
v,c
w,d
x,e
y,f
z) = a -> b -> c -> d -> e -> f -> g
f a
u b
v c
w d
x e
y f
z

-- | Query the current depth.
--
-- @since 1.0
getDepth :: Series m Depth
getDepth :: forall (m :: * -> *). Series m Depth
getDepth = forall (m :: * -> *) a. ReaderT Depth (LogicT m) a -> Series m a
Series forall r (m :: * -> *). MonadReader r m => m r
ask

-- | Run a series with a modified depth.
--
-- @since 1.0
localDepth :: (Depth -> Depth) -> Series m a -> Series m a
localDepth :: forall (m :: * -> *) a.
(Depth -> Depth) -> Series m a -> Series m a
localDepth Depth -> Depth
f (Series ReaderT Depth (LogicT m) a
a) = forall (m :: * -> *) a. ReaderT Depth (LogicT m) a -> Series m a
Series forall a b. (a -> b) -> a -> b
$ forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local Depth -> Depth
f ReaderT Depth (LogicT m) a
a

-- | Run a 'Series' with the depth decreased by 1.
--
-- If the current depth is less or equal to 0, the result is 'empty'.
--
-- @since 1.0
decDepth :: Series m a -> Series m a
decDepth :: forall (m :: * -> *) a. Series m a -> Series m a
decDepth Series m a
a = do
  forall (m :: * -> *). Series m ()
checkDepth
  forall (m :: * -> *) a.
(Depth -> Depth) -> Series m a -> Series m a
localDepth (forall a. Num a => a -> a -> a
subtract Depth
1) Series m a
a

checkDepth :: Series m ()
checkDepth :: forall (m :: * -> *). Series m ()
checkDepth = do
  Depth
d <- forall (m :: * -> *). Series m Depth
getDepth
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Depth
d forall a. Ord a => a -> a -> Bool
> Depth
0

-- | @'constM' = 'liftM' 'const'@
--
-- @since 1.1.1
constM :: Monad m => m b -> m (a -> b)
constM :: forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a b. a -> b -> a
const

-- | Fix the depth of a series at the current level. The resulting series
-- will no longer depend on the \"ambient\" depth.
--
-- @since 1.1.1
fixDepth :: Series m a -> Series m (Series m a)
fixDepth :: forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m a
s = forall (m :: * -> *). Series m Depth
getDepth forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Depth
d -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
(Depth -> Depth) -> Series m a -> Series m a
localDepth (forall a b. a -> b -> a
const Depth
d) Series m a
s

-- | If the current depth is 0, evaluate the first argument. Otherwise,
-- evaluate the second argument with decremented depth.
--
-- @since 1.1.1
decDepthChecked :: Series m a -> Series m a -> Series m a
decDepthChecked :: forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked Series m a
b Series m a
r = do
  Depth
d <- forall (m :: * -> *). Series m Depth
getDepth
  if Depth
d forall a. Ord a => a -> a -> Bool
<= Depth
0
    then Series m a
b
    else forall (m :: * -> *) a. Series m a -> Series m a
decDepth Series m a
r

unwind :: MonadLogic m => m a -> m [a]
unwind :: forall (m :: * -> *) a. MonadLogic m => m a -> m [a]
unwind m a
a =
  forall (m :: * -> *) a. MonadLogic m => m a -> m (Maybe (a, m a))
msplit m a
a forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
  forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return []) (\(a
x,m a
a') -> (a
xforall a. a -> [a] -> [a]
:) forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` forall (m :: * -> *) a. MonadLogic m => m a -> m [a]
unwind m a
a')

-- }}}

------------------------------
-- cons* and alts* functions
------------------------------
-- {{{

-- | @since 1.0
cons0 :: a -> Series m a
cons0 :: forall a (m :: * -> *). a -> Series m a
cons0 a
x = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x

-- | @since 1.0
cons1 :: Serial m a => (a->b) -> Series m b
cons1 :: forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
cons1 a -> b
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$ a -> b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | Same as 'cons1', but preserves the depth.
--
-- @since 1.0
newtypeCons :: Serial m a => (a->b) -> Series m b
newtypeCons :: forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons a -> b
f = a -> b
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.0
cons2 :: (Serial m a, Serial m b) => (a->b->c) -> Series m c
cons2 :: forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 a -> b -> c
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$ a -> b -> c
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.0
cons3 :: (Serial m a, Serial m b, Serial m c) =>
         (a->b->c->d) -> Series m d
cons3 :: forall (m :: * -> *) a b c d.
(Serial m a, Serial m b, Serial m c) =>
(a -> b -> c -> d) -> Series m d
cons3 a -> b -> c -> d
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$
  a -> b -> c -> d
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.0
cons4 :: (Serial m a, Serial m b, Serial m c, Serial m d) =>
         (a->b->c->d->e) -> Series m e
cons4 :: forall (m :: * -> *) a b c d e.
(Serial m a, Serial m b, Serial m c, Serial m d) =>
(a -> b -> c -> d -> e) -> Series m e
cons4 a -> b -> c -> d -> e
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$
  a -> b -> c -> d -> e
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.2.0
cons5 :: (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) =>
         (a->b->c->d->e->f) -> Series m f
cons5 :: forall (m :: * -> *) a b c d e f.
(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) =>
(a -> b -> c -> d -> e -> f) -> Series m f
cons5 a -> b -> c -> d -> e -> f
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$
  a -> b -> c -> d -> e -> f
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.2.0
cons6 :: (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e, Serial m f) =>
         (a->b->c->d->e->f->g) -> Series m g
cons6 :: forall (m :: * -> *) a b c d e f g.
(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e,
 Serial m f) =>
(a -> b -> c -> d -> e -> f -> g) -> Series m g
cons6 a -> b -> c -> d -> e -> f -> g
f = forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall a b. (a -> b) -> a -> b
$
  a -> b -> c -> d -> e -> f -> g
f forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series
    forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a. Serial m a => Series m a
series

-- | @since 1.0
alts0 :: Series m a -> Series m a
alts0 :: forall (m :: * -> *) a. Series m a -> Series m a
alts0 Series m a
s = Series m a
s

-- | @since 1.0
alts1 :: CoSerial m a => Series m b -> Series m (a->b)
alts1 :: forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs = do
  Series m b
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m b
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m b
rs) (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs)

-- | @since 1.0
alts2
  :: (CoSerial m a, CoSerial m b)
  => Series m c -> Series m (a->b->c)
alts2 :: forall (m :: * -> *) a b c.
(CoSerial m a, CoSerial m b) =>
Series m c -> Series m (a -> b -> c)
alts2 Series m c
rs = do
  Series m c
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m c
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked
    (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m c
rs)
    (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m c
rs)

-- | @since 1.0
alts3 ::  (CoSerial m a, CoSerial m b, CoSerial m c) =>
            Series m d -> Series m (a->b->c->d)
alts3 :: forall (m :: * -> *) a b c d.
(CoSerial m a, CoSerial m b, CoSerial m c) =>
Series m d -> Series m (a -> b -> c -> d)
alts3 Series m d
rs = do
  Series m d
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m d
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked
    (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m d
rs)
    (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m d
rs)

-- | @since 1.0
alts4 ::  (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) =>
            Series m e -> Series m (a->b->c->d->e)
alts4 :: forall (m :: * -> *) a b c d e.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) =>
Series m e -> Series m (a -> b -> c -> d -> e)
alts4 Series m e
rs = do
  Series m e
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m e
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked
    (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m e
rs)
    (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m e
rs)

-- | @since 1.2.0
alts5 ::  (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e) =>
            Series m f -> Series m (a->b->c->d->e->f)
alts5 :: forall (m :: * -> *) a b c d e f.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d,
 CoSerial m e) =>
Series m f -> Series m (a -> b -> c -> d -> e -> f)
alts5 Series m f
rs = do
  Series m f
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m f
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked
    (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m f
rs)
    (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m f
rs)

-- | @since 1.2.0
alts6 ::  (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e, CoSerial m f) =>
            Series m g -> Series m (a->b->c->d->e->f->g)
alts6 :: forall (m :: * -> *) a b c d e f g.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d,
 CoSerial m e, CoSerial m f) =>
Series m g -> Series m (a -> b -> c -> d -> e -> f -> g)
alts6 Series m g
rs = do
  Series m g
rs <- forall (m :: * -> *) a. Series m a -> Series m (Series m a)
fixDepth Series m g
rs
  forall (m :: * -> *) a. Series m a -> Series m a -> Series m a
decDepthChecked
    (forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m g
rs)
    (forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m g
rs)

-- | Same as 'alts1', but preserves the depth.
--
-- @since 1.0
newtypeAlts :: CoSerial m a => Series m b -> Series m (a->b)
newtypeAlts :: forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- }}}

------------------------------
-- Generic instances
------------------------------
-- {{{

class GSerial m f where
  gSeries :: Series m (f a)
class GCoSerial m f where
  gCoseries :: Series m b -> Series m (f a -> b)

#if __GLASGOW_HASKELL__ >= 702
instance {-# OVERLAPPABLE #-} GSerial m f => GSerial m (M1 i c f) where
  gSeries :: forall a. Series m (M1 i c f a)
gSeries = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries
  {-# INLINE gSeries #-}
instance GCoSerial m f => GCoSerial m (M1 i c f) where
  gCoseries :: forall b a. Series m b -> Series m (M1 i c f a -> b)
gCoseries Series m b
rs = (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i (c :: Meta) (f :: k -> *) (p :: k). M1 i c f p -> f p
unM1) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries Series m b
rs
  {-# INLINE gCoseries #-}

instance Serial m c => GSerial m (K1 i c) where
  gSeries :: forall a. Series m (K1 i c a)
gSeries = forall k i c (p :: k). c -> K1 i c p
K1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
  {-# INLINE gSeries #-}
instance CoSerial m c => GCoSerial m (K1 i c) where
  gCoseries :: forall b a. Series m b -> Series m (K1 i c a -> b)
gCoseries Series m b
rs = (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k i c (p :: k). K1 i c p -> c
unK1) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs
  {-# INLINE gCoseries #-}

instance GSerial m U1 where
  gSeries :: forall a. Series m (U1 a)
gSeries = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall k (p :: k). U1 p
U1
  {-# INLINE gSeries #-}
instance GCoSerial m U1 where
  gCoseries :: forall b a. Series m b -> Series m (U1 a -> b)
gCoseries Series m b
rs = forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m b
rs
  {-# INLINE gCoseries #-}

instance GSerial m V1 where
  gSeries :: forall a. Series m (V1 a)
gSeries = forall (m :: * -> *) a. MonadPlus m => m a
mzero
  {-# INLINE gSeries #-}
instance GCoSerial m V1 where
  gCoseries :: forall b a. Series m b -> Series m (V1 a -> b)
gCoseries = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return (\V1 a
a -> V1 a
a seq :: forall a b. a -> b -> b
`seq` let x :: t
x = t
x in forall {t}. t
x)
  {-# INLINE gCoseries #-}

instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :*: b) where
  gSeries :: forall a. Series m ((:*:) a b a)
gSeries = forall k (f :: k -> *) (g :: k -> *) (p :: k).
f p -> g p -> (:*:) f g p
(:*:) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries
  {-# INLINE gSeries #-}
instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :*: b) where
  gCoseries :: forall b a. Series m b -> Series m ((:*:) a b a -> b)
gCoseries Series m b
rs = forall {f :: * -> *} {p} {g :: * -> *} {t}.
(f p -> g p -> t) -> (:*:) f g p -> t
uncur forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries (forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries Series m b
rs)
      where
        uncur :: (f p -> g p -> t) -> (:*:) f g p -> t
uncur f p -> g p -> t
f (f p
x :*: g p
y) = f p -> g p -> t
f f p
x g p
y
  {-# INLINE gCoseries #-}

instance (Monad m, GSerial m a, GSerial m b) => GSerial m (a :+: b) where
  gSeries :: forall a. Series m ((:+:) a b a)
gSeries = (forall k (f :: k -> *) (g :: k -> *) (p :: k). f p -> (:+:) f g p
L1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries) forall (m :: * -> *) a. MonadLogic m => m a -> m a -> m a
`interleave` (forall k (f :: k -> *) (g :: k -> *) (p :: k). g p -> (:+:) f g p
R1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries)
  {-# INLINE gSeries #-}
instance (Monad m, GCoSerial m a, GCoSerial m b) => GCoSerial m (a :+: b) where
  gCoseries :: forall b a. Series m b -> Series m ((:+:) a b a -> b)
gCoseries Series m b
rs =
    forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \a a -> b
f ->
    forall (m :: * -> *) (f :: * -> *) b a.
GCoSerial m f =>
Series m b -> Series m (f a -> b)
gCoseries Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b a -> b
g ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
    \(:+:) a b a
e -> case (:+:) a b a
e of
      L1 a a
x -> a a -> b
f a a
x
      R1 b a
y -> b a -> b
g b a
y
  {-# INLINE gCoseries #-}

instance {-# OVERLAPPING #-} GSerial m f => GSerial m (C1 c f) where
  gSeries :: forall a. Series m (C1 c f a)
gSeries = forall k i (c :: Meta) (f :: k -> *) (p :: k). f p -> M1 i c f p
M1 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Series m a -> Series m a
decDepth forall (m :: * -> *) (f :: * -> *) a. GSerial m f => Series m (f a)
gSeries
  {-# INLINE gSeries #-}
#endif

-- }}}

------------------------------
-- Instances for basic types
------------------------------
-- {{{
instance Monad m => Serial m () where
  series :: Series m ()
series = forall (m :: * -> *) a. Monad m => a -> m a
return ()
instance Monad m => CoSerial m () where
  coseries :: forall b. Series m b -> Series m (() -> b)
coseries Series m b
rs = forall (m :: * -> *) b a. Monad m => m b -> m (a -> b)
constM Series m b
rs

instance Monad m => Serial m Integer where series :: Series m Integer
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
instance Monad m => CoSerial m Integer where coseries :: forall b. Series m b -> Series m (Integer -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.3
instance Monad m => Serial m Natural where series :: Series m Natural
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.3
instance Monad m => CoSerial m Natural where coseries :: forall b. Series m b -> Series m (Natural -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

instance Monad m => Serial m Int where series :: Series m Depth
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
instance Monad m => CoSerial m Int where coseries :: forall b. Series m b -> Series m (Depth -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.3
instance Monad m => Serial m Word where series :: Series m Word
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.3
instance Monad m => CoSerial m Word where coseries :: forall b. Series m b -> Series m (Word -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Int8 where series :: Series m Int8
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Int8 where coseries :: forall b. Series m b -> Series m (Int8 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Word8 where series :: Series m Word8
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Word8 where coseries :: forall b. Series m b -> Series m (Word8 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Int16 where series :: Series m Int16
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Int16 where coseries :: forall b. Series m b -> Series m (Int16 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Word16 where series :: Series m Word16
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Word16 where coseries :: forall b. Series m b -> Series m (Word16 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Int32 where series :: Series m Int32
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Int32 where coseries :: forall b. Series m b -> Series m (Int32 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Word32 where series :: Series m Word32
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Word32 where coseries :: forall b. Series m b -> Series m (Word32 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Int64 where series :: Series m Int64
series = forall a. M a -> a
unM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Int64 where coseries :: forall b. Series m b -> Series m (Int64 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> M a
M) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | @since 1.1.4
instance Monad m => Serial m Word64 where series :: Series m Word64
series = forall a. N a -> a
unN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.1.4
instance Monad m => CoSerial m Word64 where coseries :: forall b. Series m b -> Series m (Word64 -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> N a
N) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- | 'N' is a wrapper for 'Integral' types that causes only non-negative values
-- to be generated. Generated functions of type @N a -> b@ do not distinguish
-- different negative values of @a@.
newtype N a = N { forall a. N a -> a
unN :: a } deriving (N a -> N a -> Bool
forall a. Eq a => N a -> N a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: N a -> N a -> Bool
$c/= :: forall a. Eq a => N a -> N a -> Bool
== :: N a -> N a -> Bool
$c== :: forall a. Eq a => N a -> N a -> Bool
Eq, N a -> N a -> Bool
N a -> N a -> Ordering
N a -> N a -> N 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 (N a)
forall a. Ord a => N a -> N a -> Bool
forall a. Ord a => N a -> N a -> Ordering
forall a. Ord a => N a -> N a -> N a
min :: N a -> N a -> N a
$cmin :: forall a. Ord a => N a -> N a -> N a
max :: N a -> N a -> N a
$cmax :: forall a. Ord a => N a -> N a -> N a
>= :: N a -> N a -> Bool
$c>= :: forall a. Ord a => N a -> N a -> Bool
> :: N a -> N a -> Bool
$c> :: forall a. Ord a => N a -> N a -> Bool
<= :: N a -> N a -> Bool
$c<= :: forall a. Ord a => N a -> N a -> Bool
< :: N a -> N a -> Bool
$c< :: forall a. Ord a => N a -> N a -> Bool
compare :: N a -> N a -> Ordering
$ccompare :: forall a. Ord a => N a -> N a -> Ordering
Ord, Depth -> N a -> ShowS
forall a. Show a => Depth -> N a -> ShowS
forall a. Show a => [N a] -> ShowS
forall a. Show a => N a -> String
forall a.
(Depth -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [N a] -> ShowS
$cshowList :: forall a. Show a => [N a] -> ShowS
show :: N a -> String
$cshow :: forall a. Show a => N a -> String
showsPrec :: Depth -> N a -> ShowS
$cshowsPrec :: forall a. Show a => Depth -> N a -> ShowS
Show)

instance Real a => Real (N a) where
  toRational :: N a -> Rational
toRational (N a
x) = forall a. Real a => a -> Rational
toRational a
x

instance Enum a => Enum (N a) where
  toEnum :: Depth -> N a
toEnum Depth
x = forall a. a -> N a
N (forall a. Enum a => Depth -> a
toEnum Depth
x)
  fromEnum :: N a -> Depth
fromEnum (N a
x) = forall a. Enum a => a -> Depth
fromEnum a
x

instance Num a => Num (N a) where
  N a
x + :: N a -> N a -> N a
+ N a
y = forall a. a -> N a
N (a
x forall a. Num a => a -> a -> a
+ a
y)
  N a
x * :: N a -> N a -> N a
* N a
y = forall a. a -> N a
N (a
x forall a. Num a => a -> a -> a
* a
y)
  negate :: N a -> N a
negate (N a
x) = forall a. a -> N a
N (forall a. Num a => a -> a
negate a
x)
  abs :: N a -> N a
abs (N a
x) = forall a. a -> N a
N (forall a. Num a => a -> a
abs a
x)
  signum :: N a -> N a
signum (N a
x) = forall a. a -> N a
N (forall a. Num a => a -> a
signum a
x)
  fromInteger :: Integer -> N a
fromInteger Integer
x = forall a. a -> N a
N (forall a. Num a => Integer -> a
fromInteger Integer
x)

instance Integral a => Integral (N a) where
  quotRem :: N a -> N a -> (N a, N a)
quotRem (N a
x) (N a
y) = (forall a. a -> N a
N a
q, forall a. a -> N a
N a
r)
    where
      (a
q, a
r) = a
x forall a. Integral a => a -> a -> (a, a)
`quotRem` a
y
  toInteger :: N a -> Integer
toInteger (N a
x) = forall a. Integral a => a -> Integer
toInteger a
x

instance (Num a, Enum a, Serial m a) => Serial m (N a) where
  series :: Series m (N a)
series = forall a (m :: * -> *). (Depth -> [a]) -> Series m a
generate forall a b. (a -> b) -> a -> b
$ \Depth
d -> forall a. Depth -> [a] -> [a]
take (Depth
dforall a. Num a => a -> a -> a
+Depth
1) [N a
0..]

instance (Integral a, Monad m) => CoSerial m (N a) where
  coseries :: forall b. Series m b -> Series m (N a -> b)
coseries Series m b
rs =
    -- This is a recursive function, because @alts1 rs@ typically calls
    -- back to 'coseries' (but with lower depth).
    --
    -- The recursion stops when depth == 0. Then alts1 produces a constant
    -- function, and doesn't call back to 'coseries'.
    forall (m :: * -> *) a. Series m a -> Series m a
alts0 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
z ->
    forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \N a -> b
f ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \(N a
i) ->
      if a
i forall a. Ord a => a -> a -> Bool
> a
0
        then N a -> b
f (forall a. a -> N a
N forall a b. (a -> b) -> a -> b
$ a
iforall a. Num a => a -> a -> a
-a
1)
        else b
z

-- | 'M' is a helper type to generate values of a signed type of increasing magnitude.
newtype M a = M { forall a. M a -> a
unM :: a } deriving (M a -> M a -> Bool
forall a. Eq a => M a -> M a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: M a -> M a -> Bool
$c/= :: forall a. Eq a => M a -> M a -> Bool
== :: M a -> M a -> Bool
$c== :: forall a. Eq a => M a -> M a -> Bool
Eq, M a -> M a -> Bool
M a -> M a -> Ordering
M a -> M a -> M 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 (M a)
forall a. Ord a => M a -> M a -> Bool
forall a. Ord a => M a -> M a -> Ordering
forall a. Ord a => M a -> M a -> M a
min :: M a -> M a -> M a
$cmin :: forall a. Ord a => M a -> M a -> M a
max :: M a -> M a -> M a
$cmax :: forall a. Ord a => M a -> M a -> M a
>= :: M a -> M a -> Bool
$c>= :: forall a. Ord a => M a -> M a -> Bool
> :: M a -> M a -> Bool
$c> :: forall a. Ord a => M a -> M a -> Bool
<= :: M a -> M a -> Bool
$c<= :: forall a. Ord a => M a -> M a -> Bool
< :: M a -> M a -> Bool
$c< :: forall a. Ord a => M a -> M a -> Bool
compare :: M a -> M a -> Ordering
$ccompare :: forall a. Ord a => M a -> M a -> Ordering
Ord, Depth -> M a -> ShowS
forall a. Show a => Depth -> M a -> ShowS
forall a. Show a => [M a] -> ShowS
forall a. Show a => M a -> String
forall a.
(Depth -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [M a] -> ShowS
$cshowList :: forall a. Show a => [M a] -> ShowS
show :: M a -> String
$cshow :: forall a. Show a => M a -> String
showsPrec :: Depth -> M a -> ShowS
$cshowsPrec :: forall a. Show a => Depth -> M a -> ShowS
Show)

instance Real a => Real (M a) where
  toRational :: M a -> Rational
toRational (M a
x) = forall a. Real a => a -> Rational
toRational a
x

instance Enum a => Enum (M a) where
  toEnum :: Depth -> M a
toEnum Depth
x = forall a. a -> M a
M (forall a. Enum a => Depth -> a
toEnum Depth
x)
  fromEnum :: M a -> Depth
fromEnum (M a
x) = forall a. Enum a => a -> Depth
fromEnum a
x

instance Num a => Num (M a) where
  M a
x + :: M a -> M a -> M a
+ M a
y = forall a. a -> M a
M (a
x forall a. Num a => a -> a -> a
+ a
y)
  M a
x * :: M a -> M a -> M a
* M a
y = forall a. a -> M a
M (a
x forall a. Num a => a -> a -> a
* a
y)
  negate :: M a -> M a
negate (M a
x) = forall a. a -> M a
M (forall a. Num a => a -> a
negate a
x)
  abs :: M a -> M a
abs (M a
x) = forall a. a -> M a
M (forall a. Num a => a -> a
abs a
x)
  signum :: M a -> M a
signum (M a
x) = forall a. a -> M a
M (forall a. Num a => a -> a
signum a
x)
  fromInteger :: Integer -> M a
fromInteger Integer
x = forall a. a -> M a
M (forall a. Num a => Integer -> a
fromInteger Integer
x)

instance Integral a => Integral (M a) where
  quotRem :: M a -> M a -> (M a, M a)
quotRem (M a
x) (M a
y) = (forall a. a -> M a
M a
q, forall a. a -> M a
M a
r)
    where
      (a
q, a
r) = a
x forall a. Integral a => a -> a -> (a, a)
`quotRem` a
y
  toInteger :: M a -> Integer
toInteger (M a
x) = forall a. Integral a => a -> Integer
toInteger a
x

instance (Num a, Enum a, Monad m) => Serial m (M a) where
  series :: Series m (M a)
series = forall {m :: * -> *}. Series m (M a)
others forall (m :: * -> *) a. MonadLogic m => m a -> m a -> m a
`interleave` forall {m :: * -> *}. Series m (M a)
positives
    where positives :: Series m (M a)
positives = forall a (m :: * -> *). (Depth -> [a]) -> Series m a
generate forall a b. (a -> b) -> a -> b
$ \Depth
d -> forall a. Depth -> [a] -> [a]
take Depth
d [M a
1..]
          others :: Series m (M a)
others = forall a (m :: * -> *). (Depth -> [a]) -> Series m a
generate forall a b. (a -> b) -> a -> b
$ \Depth
d -> forall a. Depth -> [a] -> [a]
take (Depth
dforall a. Num a => a -> a -> a
+Depth
1) [M a
0,-M a
1..]

instance (Ord a, Num a, Monad m) => CoSerial m (M a) where
  coseries :: forall b. Series m b -> Series m (M a -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a. Series m a -> Series m a
alts0 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
z ->
    forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \M (M a) -> b
f ->
    forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \M (M a) -> b
g ->
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ \ M a
i -> case forall a. Ord a => a -> a -> Ordering
compare M a
i M a
0 of
        Ordering
GT -> M (M a) -> b
f (forall a. a -> M a
M (M a
i forall a. Num a => a -> a -> a
- M a
1))
        Ordering
LT -> M (M a) -> b
g (forall a. a -> M a
M (forall a. Num a => a -> a
abs M a
i forall a. Num a => a -> a -> a
- M a
1))
        Ordering
EQ -> b
z

instance Monad m => Serial m Float where
  series :: Series m Float
series =
    forall (m :: * -> *) a. Serial m a => Series m a
series forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \(Integer
sig, Depth
exp) ->
    forall (f :: * -> *). Alternative f => Bool -> f ()
guard (forall a. Integral a => a -> Bool
odd Integer
sig Bool -> Bool -> Bool
|| Integer
sigforall a. Eq a => a -> a -> Bool
==Integer
0 Bool -> Bool -> Bool
&& Depth
expforall a. Eq a => a -> a -> Bool
==Depth
0) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
    forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. RealFloat a => Integer -> Depth -> a
encodeFloat Integer
sig Depth
exp)
instance Monad m => CoSerial m Float where
  coseries :: forall b. Series m b -> Series m (Float -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \(Integer, Depth) -> b
f ->
      forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (Integer, Depth) -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RealFloat a => a -> (Integer, Depth)
decodeFloat

instance Monad m => Serial m Double where
  series :: Series m Double
series = (forall a b. (Real a, Fractional b) => a -> b
realToFrac :: Float -> Double) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
instance Monad m => CoSerial m Double where
  coseries :: forall b. Series m b -> Series m (Double -> b)
coseries Series m b
rs =
    (forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. (Real a, Fractional b) => a -> b
realToFrac :: Double -> Float)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs

-- | @since 1.1
instance (Integral i, Serial m i) => Serial m (Ratio i) where
  series :: Series m (Ratio i)
series = forall {a}. Integral a => (a, Positive a) -> Ratio a
pairToRatio forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
    where
      pairToRatio :: (a, Positive a) -> Ratio a
pairToRatio (a
n, Positive a
d) = a
n forall a. Integral a => a -> a -> Ratio a
% a
d
-- | @since 1.1
instance (Integral i, CoSerial m i) => CoSerial m (Ratio i) where
  coseries :: forall b. Series m b -> Series m (Ratio i -> b)
coseries Series m b
rs = (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {b}. Ratio b -> (b, b)
ratioToPair) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs
    where
      ratioToPair :: Ratio b -> (b, b)
ratioToPair Ratio b
r = (forall a. Ratio a -> a
numerator Ratio b
r, forall a. Ratio a -> a
denominator Ratio b
r)

instance Monad m => Serial m Char where
  series :: Series m Char
series = forall a (m :: * -> *). (Depth -> [a]) -> Series m a
generate forall a b. (a -> b) -> a -> b
$ \Depth
d -> forall a. Depth -> [a] -> [a]
take (Depth
dforall a. Num a => a -> a -> a
+Depth
1) [Char
'a'..Char
'z']
instance Monad m => CoSerial m Char where
  coseries :: forall b. Series m b -> Series m (Char -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \N Depth -> b
f ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \Char
c -> N Depth -> b
f (forall a. a -> N a
N (forall a. Enum a => a -> Depth
fromEnum Char
c forall a. Num a => a -> a -> a
- forall a. Enum a => a -> Depth
fromEnum Char
'a'))

instance (Serial m a, Serial m b) => Serial m (a,b) where
  series :: Series m (a, b)
series = forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 (,)
instance (CoSerial m a, CoSerial m b) => CoSerial m (a,b) where
  coseries :: forall b. Series m b -> Series m ((a, b) -> b)
coseries Series m b
rs = forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c.
(CoSerial m a, CoSerial m b) =>
Series m c -> Series m (a -> b -> c)
alts2 Series m b
rs

instance (Serial m a, Serial m b, Serial m c) => Serial m (a,b,c) where
  series :: Series m (a, b, c)
series = forall (m :: * -> *) a b c d.
(Serial m a, Serial m b, Serial m c) =>
(a -> b -> c -> d) -> Series m d
cons3 (,,)
instance (CoSerial m a, CoSerial m b, CoSerial m c) => CoSerial m (a,b,c) where
  coseries :: forall b. Series m b -> Series m ((a, b, c) -> b)
coseries Series m b
rs = forall a b c d. (a -> b -> c -> d) -> (a, b, c) -> d
uncurry3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c d.
(CoSerial m a, CoSerial m b, CoSerial m c) =>
Series m d -> Series m (a -> b -> c -> d)
alts3 Series m b
rs

instance (Serial m a, Serial m b, Serial m c, Serial m d) => Serial m (a,b,c,d) where
  series :: Series m (a, b, c, d)
series = forall (m :: * -> *) a b c d e.
(Serial m a, Serial m b, Serial m c, Serial m d) =>
(a -> b -> c -> d -> e) -> Series m e
cons4 (,,,)
instance (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) => CoSerial m (a,b,c,d) where
  coseries :: forall b. Series m b -> Series m ((a, b, c, d) -> b)
coseries Series m b
rs = forall a b c d e. (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
uncurry4 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c d e.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d) =>
Series m e -> Series m (a -> b -> c -> d -> e)
alts4 Series m b
rs

-- | @since 1.2.0
instance (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) => Serial m (a,b,c,d,e) where
  series :: Series m (a, b, c, d, e)
series = forall (m :: * -> *) a b c d e f.
(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e) =>
(a -> b -> c -> d -> e -> f) -> Series m f
cons5 (,,,,)
-- | @since 1.2.0
instance (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e) => CoSerial m (a,b,c,d,e) where
  coseries :: forall b. Series m b -> Series m ((a, b, c, d, e) -> b)
coseries Series m b
rs = forall a b c d e f.
(a -> b -> c -> d -> e -> f) -> (a, b, c, d, e) -> f
uncurry5 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c d e f.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d,
 CoSerial m e) =>
Series m f -> Series m (a -> b -> c -> d -> e -> f)
alts5 Series m b
rs

-- | @since 1.2.0
instance (Serial m a, Serial m b, Serial m c, Serial m d, Serial m e, Serial m f) => Serial m (a,b,c,d,e,f) where
  series :: Series m (a, b, c, d, e, f)
series = forall (m :: * -> *) a b c d e f g.
(Serial m a, Serial m b, Serial m c, Serial m d, Serial m e,
 Serial m f) =>
(a -> b -> c -> d -> e -> f -> g) -> Series m g
cons6 (,,,,,)
-- | @since 1.2.0
instance (CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d, CoSerial m e, CoSerial m f) => CoSerial m (a,b,c,d,e,f) where
  coseries :: forall b. Series m b -> Series m ((a, b, c, d, e, f) -> b)
coseries Series m b
rs = forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g) -> (a, b, c, d, e, f) -> g
uncurry6 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c d e f g.
(CoSerial m a, CoSerial m b, CoSerial m c, CoSerial m d,
 CoSerial m e, CoSerial m f) =>
Series m g -> Series m (a -> b -> c -> d -> e -> f -> g)
alts6 Series m b
rs

instance Monad m => Serial m Bool where
  series :: Series m Bool
series = forall a (m :: * -> *). a -> Series m a
cons0 Bool
True forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall a (m :: * -> *). a -> Series m a
cons0 Bool
False
instance Monad m => CoSerial m Bool where
  coseries :: forall b. Series m b -> Series m (Bool -> b)
coseries Series m b
rs =
    Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
r1 ->
    Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
r2 ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \Bool
x -> if Bool
x then b
r1 else b
r2

-- | @since 1.2.1
instance Monad m => Serial m Ordering where
  series :: Series m Ordering
series = forall a (m :: * -> *). a -> Series m a
cons0 Ordering
LT forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall a (m :: * -> *). a -> Series m a
cons0 Ordering
EQ forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall a (m :: * -> *). a -> Series m a
cons0 Ordering
GT
-- | @since 1.2.1
instance Monad m => CoSerial m Ordering where
  coseries :: forall b. Series m b -> Series m (Ordering -> b)
coseries Series m b
rs =
    Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
r1 ->
    Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
r2 ->
    Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
r3 ->
    forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ \Ordering
x -> case Ordering
x of
        Ordering
LT -> b
r1
        Ordering
EQ -> b
r2
        Ordering
GT -> b
r3

instance (Serial m a) => Serial m (Maybe a) where
  series :: Series m (Maybe a)
series = forall a (m :: * -> *). a -> Series m a
cons0 forall a. Maybe a
Nothing forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
cons1 forall a. a -> Maybe a
Just
instance (CoSerial m a) => CoSerial m (Maybe a) where
  coseries :: forall b. Series m b -> Series m (Maybe a -> b)
coseries Series m b
rs =
    forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Series m a -> Series m a
alts0 Series m b
rs forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs

instance (Serial m a, Serial m b) => Serial m (Either a b) where
  series :: Series m (Either a b)
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
cons1 forall a b. a -> Either a b
Left forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
cons1 forall a b. b -> Either a b
Right
instance (CoSerial m a, CoSerial m b) => CoSerial m (Either a b) where
  coseries :: forall b. Series m b -> Series m (Either a b -> b)
coseries Series m b
rs =
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs forall (m :: * -> *) a b.
Monad m =>
Series m (a -> b) -> Series m a -> Series m b
<~> forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
alts1 Series m b
rs

instance Serial m a => Serial m [a] where
  series :: Series m [a]
series = forall a (m :: * -> *). a -> Series m a
cons0 [] forall (m :: * -> *) a.
Monad m =>
Series m a -> Series m a -> Series m a
\/ forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 (:)
instance CoSerial m a => CoSerial m [a] where
  coseries :: forall b. Series m b -> Series m ([a] -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a. Series m a -> Series m a
alts0 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \b
y ->
    forall (m :: * -> *) a b c.
(CoSerial m a, CoSerial m b) =>
Series m c -> Series m (a -> b -> c)
alts2 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \a -> [a] -> b
f ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \[a]
xs -> case [a]
xs of [] -> b
y; a
x:[a]
xs' -> a -> [a] -> b
f a
x [a]
xs'

-- | @since 1.2.0
instance Serial m a => Serial m (NE.NonEmpty a) where
  series :: Series m (NonEmpty a)
series = forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 forall a. a -> [a] -> NonEmpty a
(NE.:|)

-- | @since 1.2.0
instance CoSerial m a => CoSerial m (NE.NonEmpty a) where
  coseries :: forall b. Series m b -> Series m (NonEmpty a -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a b c.
(CoSerial m a, CoSerial m b) =>
Series m c -> Series m (a -> b -> c)
alts2 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \a -> [a] -> b
f ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \(a
x NE.:| [a]
xs') -> a -> [a] -> b
f a
x [a]
xs'

#if MIN_VERSION_base(4,4,0)
-- | @since 1.2.0
instance Serial m a => Serial m (Complex a) where
#else
-- | @since 1.2.0
instance (RealFloat a, Serial m a) => Serial m (Complex a) where
#endif
  series :: Series m (Complex a)
series = forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 forall a. a -> a -> Complex a
(:+)

#if MIN_VERSION_base(4,4,0)
-- | @since 1.2.0
instance CoSerial m a => CoSerial m (Complex a) where
#else
-- | @since 1.2.0
instance (RealFloat a, CoSerial m a) => CoSerial m (Complex a) where
#endif
  coseries :: forall b. Series m b -> Series m (Complex a -> b)
coseries Series m b
rs =
    forall (m :: * -> *) a b c.
(CoSerial m a, CoSerial m b) =>
Series m c -> Series m (a -> b -> c)
alts2 Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \a -> a -> b
f ->
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \(a
x :+ a
xs') -> a -> a -> b
f a
x a
xs'

-- | @since 1.2.0
instance Monad m => Serial m Void where
  series :: Series m Void
series = forall (m :: * -> *) a. MonadPlus m => m a
mzero

-- | @since 1.2.0
instance Monad m => CoSerial m Void where
  coseries :: forall b. Series m b -> Series m (Void -> b)
coseries = forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Void -> a
absurd

instance (CoSerial m a, Serial m b) => Serial m (a->b) where
  series :: Series m (a -> b)
series = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall (m :: * -> *) a. Serial m a => Series m a
series
-- Thanks to Ralf Hinze for the definition of coseries
-- using the nest auxiliary.
instance (Serial m a, CoSerial m a, Serial m b, CoSerial m b) => CoSerial m (a->b) where
  coseries :: forall b. Series m b -> Series m ((a -> b) -> b)
coseries Series m b
r = do
    [a]
args <- forall (m :: * -> *) a. MonadLogic m => m a -> m [a]
unwind forall (m :: * -> *) a. Serial m a => Series m a
series

    [b] -> b
g <- forall a b (m :: * -> *) c.
(Serial m b, CoSerial m b) =>
Series m c -> [a] -> Series m ([b] -> c)
nest Series m b
r [a]
args
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \a -> b
f -> [b] -> b
g forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map a -> b
f [a]
args

    where

    nest :: forall a b m c . (Serial m b, CoSerial m b) => Series m c -> [a] -> Series m ([b] -> c)
    nest :: forall a b (m :: * -> *) c.
(Serial m b, CoSerial m b) =>
Series m c -> [a] -> Series m ([b] -> c)
nest Series m c
rs [a]
args = do
      case [a]
args of
        [] -> forall a b. a -> b -> a
const forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` Series m c
rs
        a
_:[a]
rest -> do
          let sf :: Series m (b -> [b] -> c)
sf = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries forall a b. (a -> b) -> a -> b
$ forall a b (m :: * -> *) c.
(Serial m b, CoSerial m b) =>
Series m c -> [a] -> Series m ([b] -> c)
nest Series m c
rs [a]
rest
          b -> [b] -> c
f <- Series m (b -> [b] -> c)
sf
          forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \(b
b:[b]
bs) -> b -> [b] -> c
f b
b [b]
bs

-- show the extension of a function (in part, bounded both by
-- the number and depth of arguments)
instance (Serial Identity a, Show a, Show b) => Show (a -> b) where
  show :: (a -> b) -> String
show a -> b
f =
    if Depth
maxarheight forall a. Eq a => a -> a -> Bool
== Depth
1
    Bool -> Bool -> Bool
&& Depth
sumarwidth forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. Foldable t => t a -> Depth
length [(String, String)]
ars forall a. Num a => a -> a -> a
* forall (t :: * -> *) a. Foldable t => t a -> Depth
length String
"->;" forall a. Ord a => a -> a -> Bool
< Depth
widthLimit then
      String
"{"forall a. [a] -> [a] -> [a]
++
      forall a. [a] -> [[a]] -> [a]
intercalate String
";" [String
aforall a. [a] -> [a] -> [a]
++String
"->"forall a. [a] -> [a] -> [a]
++String
r | (String
a,String
r) <- [(String, String)]
ars]
      forall a. [a] -> [a] -> [a]
++String
"}"
    else
      forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ [String
aforall a. [a] -> [a] -> [a]
++String
"->\n"forall a. [a] -> [a] -> [a]
++ShowS
indent String
r | (String
a,String
r) <- [(String, String)]
ars]
    where
    ars :: [(String, String)]
ars = forall a. Depth -> [a] -> [a]
take Depth
lengthLimit [ (forall a. Show a => a -> String
show a
x, forall a. Show a => a -> String
show (a -> b
f a
x))
                           | a
x <- forall a. Depth -> Series Identity a -> [a]
list Depth
depthLimit forall (m :: * -> *) a. Serial m a => Series m a
series ]
    maxarheight :: Depth
maxarheight = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum  [ forall a. Ord a => a -> a -> a
max (String -> Depth
height String
a) (String -> Depth
height String
r)
                           | (String
a,String
r) <- [(String, String)]
ars ]
    sumarwidth :: Depth
sumarwidth = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum       [ forall (t :: * -> *) a. Foldable t => t a -> Depth
length String
a forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. Foldable t => t a -> Depth
length String
r
                           | (String
a,String
r) <- [(String, String)]
ars]
    indent :: ShowS
indent = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (String
"  "forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
    height :: String -> Depth
height = forall (t :: * -> *) a. Foldable t => t a -> Depth
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
    (Depth
widthLimit,Depth
lengthLimit,Depth
depthLimit) = (Depth
80,Depth
20,Depth
3)::(Int,Int,Depth)

-- | @since 1.2.0
instance (Monad m, Serial m (f (g a))) => Serial m (Compose f g a) where
  series :: Series m (Compose f g a)
series = forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series
-- | @since 1.2.0
instance (Monad m, CoSerial m (f (g a))) => CoSerial m (Compose f g a) where
  coseries :: forall b. Series m b -> Series m (Compose f g a -> b)
coseries = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
coseries

-- }}}

------------------------------
-- Convenient wrappers
------------------------------
-- {{{

--------------------------------------------------------------------------
-- | 'Positive' @x@ guarantees that \( x > 0 \).
--
-- @since 1.0
newtype Positive a = Positive { forall a. Positive a -> a
getPositive :: a }
  deriving
  ( Positive a -> Positive a -> Bool
forall a. Eq a => Positive a -> Positive a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Positive a -> Positive a -> Bool
$c/= :: forall a. Eq a => Positive a -> Positive a -> Bool
== :: Positive a -> Positive a -> Bool
$c== :: forall a. Eq a => Positive a -> Positive a -> Bool
Eq
  , Positive a -> Positive a -> Bool
Positive a -> Positive a -> Ordering
Positive a -> Positive a -> Positive 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 (Positive a)
forall a. Ord a => Positive a -> Positive a -> Bool
forall a. Ord a => Positive a -> Positive a -> Ordering
forall a. Ord a => Positive a -> Positive a -> Positive a
min :: Positive a -> Positive a -> Positive a
$cmin :: forall a. Ord a => Positive a -> Positive a -> Positive a
max :: Positive a -> Positive a -> Positive a
$cmax :: forall a. Ord a => Positive a -> Positive a -> Positive a
>= :: Positive a -> Positive a -> Bool
$c>= :: forall a. Ord a => Positive a -> Positive a -> Bool
> :: Positive a -> Positive a -> Bool
$c> :: forall a. Ord a => Positive a -> Positive a -> Bool
<= :: Positive a -> Positive a -> Bool
$c<= :: forall a. Ord a => Positive a -> Positive a -> Bool
< :: Positive a -> Positive a -> Bool
$c< :: forall a. Ord a => Positive a -> Positive a -> Bool
compare :: Positive a -> Positive a -> Ordering
$ccompare :: forall a. Ord a => Positive a -> Positive a -> Ordering
Ord
  , forall a b. a -> Positive b -> Positive a
forall a b. (a -> b) -> Positive a -> Positive b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Positive b -> Positive a
$c<$ :: forall a b. a -> Positive b -> Positive a
fmap :: forall a b. (a -> b) -> Positive a -> Positive b
$cfmap :: forall a b. (a -> b) -> Positive a -> Positive b
Functor     -- ^ @since 1.2.0
  , forall a. Eq a => a -> Positive a -> Bool
forall a. Num a => Positive a -> a
forall a. Ord a => Positive a -> a
forall m. Monoid m => Positive m -> m
forall a. Positive a -> Bool
forall a. Positive a -> Depth
forall a. Positive a -> [a]
forall a. (a -> a -> a) -> Positive a -> a
forall m a. Monoid m => (a -> m) -> Positive a -> m
forall b a. (b -> a -> b) -> b -> Positive a -> b
forall a b. (a -> b -> b) -> b -> Positive a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Depth)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Positive a -> a
$cproduct :: forall a. Num a => Positive a -> a
sum :: forall a. Num a => Positive a -> a
$csum :: forall a. Num a => Positive a -> a
minimum :: forall a. Ord a => Positive a -> a
$cminimum :: forall a. Ord a => Positive a -> a
maximum :: forall a. Ord a => Positive a -> a
$cmaximum :: forall a. Ord a => Positive a -> a
elem :: forall a. Eq a => a -> Positive a -> Bool
$celem :: forall a. Eq a => a -> Positive a -> Bool
length :: forall a. Positive a -> Depth
$clength :: forall a. Positive a -> Depth
null :: forall a. Positive a -> Bool
$cnull :: forall a. Positive a -> Bool
toList :: forall a. Positive a -> [a]
$ctoList :: forall a. Positive a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Positive a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Positive a -> a
foldr1 :: forall a. (a -> a -> a) -> Positive a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Positive a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Positive a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Positive a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Positive a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Positive a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Positive a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Positive a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Positive a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Positive a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Positive a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Positive a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Positive a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Positive a -> m
fold :: forall m. Monoid m => Positive m -> m
$cfold :: forall m. Monoid m => Positive m -> m
Foldable    -- ^ @since 1.2.0
  , Functor Positive
Foldable Positive
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Positive (m a) -> m (Positive a)
forall (f :: * -> *) a.
Applicative f =>
Positive (f a) -> f (Positive a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Positive a -> m (Positive b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Positive a -> f (Positive b)
sequence :: forall (m :: * -> *) a. Monad m => Positive (m a) -> m (Positive a)
$csequence :: forall (m :: * -> *) a. Monad m => Positive (m a) -> m (Positive a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Positive a -> m (Positive b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Positive a -> m (Positive b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Positive (f a) -> f (Positive a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Positive (f a) -> f (Positive a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Positive a -> f (Positive b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Positive a -> f (Positive b)
Traversable -- ^ @since 1.2.0
  )

instance Real a => Real (Positive a) where
  toRational :: Positive a -> Rational
toRational (Positive a
x) = forall a. Real a => a -> Rational
toRational a
x

-- | @since 1.2.0
instance (Num a, Bounded a) => Bounded (Positive a) where
  minBound :: Positive a
minBound = forall a. a -> Positive a
Positive a
1
  maxBound :: Positive a
maxBound = forall a. a -> Positive a
Positive (forall a. Bounded a => a
maxBound :: a)

instance Enum a => Enum (Positive a) where
  toEnum :: Depth -> Positive a
toEnum Depth
x = forall a. a -> Positive a
Positive (forall a. Enum a => Depth -> a
toEnum Depth
x)
  fromEnum :: Positive a -> Depth
fromEnum (Positive a
x) = forall a. Enum a => a -> Depth
fromEnum a
x

instance Num a => Num (Positive a) where
  Positive a
x + :: Positive a -> Positive a -> Positive a
+ Positive a
y = forall a. a -> Positive a
Positive (a
x forall a. Num a => a -> a -> a
+ a
y)
  Positive a
x * :: Positive a -> Positive a -> Positive a
* Positive a
y = forall a. a -> Positive a
Positive (a
x forall a. Num a => a -> a -> a
* a
y)
  negate :: Positive a -> Positive a
negate (Positive a
x) = forall a. a -> Positive a
Positive (forall a. Num a => a -> a
negate a
x)
  abs :: Positive a -> Positive a
abs (Positive a
x) = forall a. a -> Positive a
Positive (forall a. Num a => a -> a
abs a
x)
  signum :: Positive a -> Positive a
signum (Positive a
x) = forall a. a -> Positive a
Positive (forall a. Num a => a -> a
signum a
x)
  fromInteger :: Integer -> Positive a
fromInteger Integer
x = forall a. a -> Positive a
Positive (forall a. Num a => Integer -> a
fromInteger Integer
x)

instance Integral a => Integral (Positive a) where
  quotRem :: Positive a -> Positive a -> (Positive a, Positive a)
quotRem (Positive a
x) (Positive a
y) = (forall a. a -> Positive a
Positive a
q, forall a. a -> Positive a
Positive a
r)
    where
      (a
q, a
r) = a
x forall a. Integral a => a -> a -> (a, a)
`quotRem` a
y
  toInteger :: Positive a -> Integer
toInteger (Positive a
x) = forall a. Integral a => a -> Integer
toInteger a
x

instance (Num a, Ord a, Serial m a) => Serial m (Positive a) where
  series :: Series m (Positive a)
series = forall a. a -> Positive a
Positive forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series forall (m :: * -> *) a. Series m a -> (a -> Bool) -> Series m a
`suchThat` (forall a. Ord a => a -> a -> Bool
> a
0)

instance Show a => Show (Positive a) where
  showsPrec :: Depth -> Positive a -> ShowS
showsPrec Depth
n (Positive a
x) = forall a. Show a => Depth -> a -> ShowS
showsPrec Depth
n a
x

-- | 'NonNegative' @x@ guarantees that \( x \ge 0 \).
--
-- @since 1.0
newtype NonNegative a = NonNegative { forall a. NonNegative a -> a
getNonNegative :: a }
  deriving
  ( NonNegative a -> NonNegative a -> Bool
forall a. Eq a => NonNegative a -> NonNegative a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NonNegative a -> NonNegative a -> Bool
$c/= :: forall a. Eq a => NonNegative a -> NonNegative a -> Bool
== :: NonNegative a -> NonNegative a -> Bool
$c== :: forall a. Eq a => NonNegative a -> NonNegative a -> Bool
Eq
  , NonNegative a -> NonNegative a -> Bool
NonNegative a -> NonNegative a -> Ordering
NonNegative a -> NonNegative a -> NonNegative 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 (NonNegative a)
forall a. Ord a => NonNegative a -> NonNegative a -> Bool
forall a. Ord a => NonNegative a -> NonNegative a -> Ordering
forall a. Ord a => NonNegative a -> NonNegative a -> NonNegative a
min :: NonNegative a -> NonNegative a -> NonNegative a
$cmin :: forall a. Ord a => NonNegative a -> NonNegative a -> NonNegative a
max :: NonNegative a -> NonNegative a -> NonNegative a
$cmax :: forall a. Ord a => NonNegative a -> NonNegative a -> NonNegative a
>= :: NonNegative a -> NonNegative a -> Bool
$c>= :: forall a. Ord a => NonNegative a -> NonNegative a -> Bool
> :: NonNegative a -> NonNegative a -> Bool
$c> :: forall a. Ord a => NonNegative a -> NonNegative a -> Bool
<= :: NonNegative a -> NonNegative a -> Bool
$c<= :: forall a. Ord a => NonNegative a -> NonNegative a -> Bool
< :: NonNegative a -> NonNegative a -> Bool
$c< :: forall a. Ord a => NonNegative a -> NonNegative a -> Bool
compare :: NonNegative a -> NonNegative a -> Ordering
$ccompare :: forall a. Ord a => NonNegative a -> NonNegative a -> Ordering
Ord
  , forall a b. a -> NonNegative b -> NonNegative a
forall a b. (a -> b) -> NonNegative a -> NonNegative b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> NonNegative b -> NonNegative a
$c<$ :: forall a b. a -> NonNegative b -> NonNegative a
fmap :: forall a b. (a -> b) -> NonNegative a -> NonNegative b
$cfmap :: forall a b. (a -> b) -> NonNegative a -> NonNegative b
Functor     -- ^ @since 1.2.0
  , forall a. Eq a => a -> NonNegative a -> Bool
forall a. Num a => NonNegative a -> a
forall a. Ord a => NonNegative a -> a
forall m. Monoid m => NonNegative m -> m
forall a. NonNegative a -> Bool
forall a. NonNegative a -> Depth
forall a. NonNegative a -> [a]
forall a. (a -> a -> a) -> NonNegative a -> a
forall m a. Monoid m => (a -> m) -> NonNegative a -> m
forall b a. (b -> a -> b) -> b -> NonNegative a -> b
forall a b. (a -> b -> b) -> b -> NonNegative a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Depth)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => NonNegative a -> a
$cproduct :: forall a. Num a => NonNegative a -> a
sum :: forall a. Num a => NonNegative a -> a
$csum :: forall a. Num a => NonNegative a -> a
minimum :: forall a. Ord a => NonNegative a -> a
$cminimum :: forall a. Ord a => NonNegative a -> a
maximum :: forall a. Ord a => NonNegative a -> a
$cmaximum :: forall a. Ord a => NonNegative a -> a
elem :: forall a. Eq a => a -> NonNegative a -> Bool
$celem :: forall a. Eq a => a -> NonNegative a -> Bool
length :: forall a. NonNegative a -> Depth
$clength :: forall a. NonNegative a -> Depth
null :: forall a. NonNegative a -> Bool
$cnull :: forall a. NonNegative a -> Bool
toList :: forall a. NonNegative a -> [a]
$ctoList :: forall a. NonNegative a -> [a]
foldl1 :: forall a. (a -> a -> a) -> NonNegative a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> NonNegative a -> a
foldr1 :: forall a. (a -> a -> a) -> NonNegative a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> NonNegative a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> NonNegative a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> NonNegative a -> b
foldl :: forall b a. (b -> a -> b) -> b -> NonNegative a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> NonNegative a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> NonNegative a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> NonNegative a -> b
foldr :: forall a b. (a -> b -> b) -> b -> NonNegative a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> NonNegative a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> NonNegative a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> NonNegative a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> NonNegative a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> NonNegative a -> m
fold :: forall m. Monoid m => NonNegative m -> m
$cfold :: forall m. Monoid m => NonNegative m -> m
Foldable    -- ^ @since 1.2.0
  , Functor NonNegative
Foldable NonNegative
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
NonNegative (m a) -> m (NonNegative a)
forall (f :: * -> *) a.
Applicative f =>
NonNegative (f a) -> f (NonNegative a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonNegative a -> m (NonNegative b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonNegative a -> f (NonNegative b)
sequence :: forall (m :: * -> *) a.
Monad m =>
NonNegative (m a) -> m (NonNegative a)
$csequence :: forall (m :: * -> *) a.
Monad m =>
NonNegative (m a) -> m (NonNegative a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonNegative a -> m (NonNegative b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonNegative a -> m (NonNegative b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
NonNegative (f a) -> f (NonNegative a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
NonNegative (f a) -> f (NonNegative a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonNegative a -> f (NonNegative b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonNegative a -> f (NonNegative b)
Traversable -- ^ @since 1.2.0
  )

instance Real a => Real (NonNegative a) where
  toRational :: NonNegative a -> Rational
toRational (NonNegative a
x) = forall a. Real a => a -> Rational
toRational a
x

-- | @since 1.2.0
instance (Num a, Bounded a) => Bounded (NonNegative a) where
  minBound :: NonNegative a
minBound = forall a. a -> NonNegative a
NonNegative a
0
  maxBound :: NonNegative a
maxBound = forall a. a -> NonNegative a
NonNegative (forall a. Bounded a => a
maxBound :: a)

instance Enum a => Enum (NonNegative a) where
  toEnum :: Depth -> NonNegative a
toEnum Depth
x = forall a. a -> NonNegative a
NonNegative (forall a. Enum a => Depth -> a
toEnum Depth
x)
  fromEnum :: NonNegative a -> Depth
fromEnum (NonNegative a
x) = forall a. Enum a => a -> Depth
fromEnum a
x

instance Num a => Num (NonNegative a) where
  NonNegative a
x + :: NonNegative a -> NonNegative a -> NonNegative a
+ NonNegative a
y = forall a. a -> NonNegative a
NonNegative (a
x forall a. Num a => a -> a -> a
+ a
y)
  NonNegative a
x * :: NonNegative a -> NonNegative a -> NonNegative a
* NonNegative a
y = forall a. a -> NonNegative a
NonNegative (a
x forall a. Num a => a -> a -> a
* a
y)
  negate :: NonNegative a -> NonNegative a
negate (NonNegative a
x) = forall a. a -> NonNegative a
NonNegative (forall a. Num a => a -> a
negate a
x)
  abs :: NonNegative a -> NonNegative a
abs (NonNegative a
x) = forall a. a -> NonNegative a
NonNegative (forall a. Num a => a -> a
abs a
x)
  signum :: NonNegative a -> NonNegative a
signum (NonNegative a
x) = forall a. a -> NonNegative a
NonNegative (forall a. Num a => a -> a
signum a
x)
  fromInteger :: Integer -> NonNegative a
fromInteger Integer
x = forall a. a -> NonNegative a
NonNegative (forall a. Num a => Integer -> a
fromInteger Integer
x)

instance Integral a => Integral (NonNegative a) where
  quotRem :: NonNegative a -> NonNegative a -> (NonNegative a, NonNegative a)
quotRem (NonNegative a
x) (NonNegative a
y) = (forall a. a -> NonNegative a
NonNegative a
q, forall a. a -> NonNegative a
NonNegative a
r)
    where
      (a
q, a
r) = a
x forall a. Integral a => a -> a -> (a, a)
`quotRem` a
y
  toInteger :: NonNegative a -> Integer
toInteger (NonNegative a
x) = forall a. Integral a => a -> Integer
toInteger a
x

instance (Num a, Ord a, Serial m a) => Serial m (NonNegative a) where
  series :: Series m (NonNegative a)
series = forall a. a -> NonNegative a
NonNegative forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series forall (m :: * -> *) a. Series m a -> (a -> Bool) -> Series m a
`suchThat` (forall a. Ord a => a -> a -> Bool
>= a
0)

instance Show a => Show (NonNegative a) where
  showsPrec :: Depth -> NonNegative a -> ShowS
showsPrec Depth
n (NonNegative a
x) = forall a. Show a => Depth -> a -> ShowS
showsPrec Depth
n a
x

-- | 'NonZero' @x@ guarantees that \( x \ne 0 \).
--
-- @since 1.2.0
newtype NonZero a = NonZero { forall a. NonZero a -> a
getNonZero :: a }
 deriving (NonZero a -> NonZero a -> Bool
forall a. Eq a => NonZero a -> NonZero a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NonZero a -> NonZero a -> Bool
$c/= :: forall a. Eq a => NonZero a -> NonZero a -> Bool
== :: NonZero a -> NonZero a -> Bool
$c== :: forall a. Eq a => NonZero a -> NonZero a -> Bool
Eq, NonZero a -> NonZero a -> Bool
NonZero a -> NonZero a -> Ordering
NonZero a -> NonZero a -> NonZero 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 (NonZero a)
forall a. Ord a => NonZero a -> NonZero a -> Bool
forall a. Ord a => NonZero a -> NonZero a -> Ordering
forall a. Ord a => NonZero a -> NonZero a -> NonZero a
min :: NonZero a -> NonZero a -> NonZero a
$cmin :: forall a. Ord a => NonZero a -> NonZero a -> NonZero a
max :: NonZero a -> NonZero a -> NonZero a
$cmax :: forall a. Ord a => NonZero a -> NonZero a -> NonZero a
>= :: NonZero a -> NonZero a -> Bool
$c>= :: forall a. Ord a => NonZero a -> NonZero a -> Bool
> :: NonZero a -> NonZero a -> Bool
$c> :: forall a. Ord a => NonZero a -> NonZero a -> Bool
<= :: NonZero a -> NonZero a -> Bool
$c<= :: forall a. Ord a => NonZero a -> NonZero a -> Bool
< :: NonZero a -> NonZero a -> Bool
$c< :: forall a. Ord a => NonZero a -> NonZero a -> Bool
compare :: NonZero a -> NonZero a -> Ordering
$ccompare :: forall a. Ord a => NonZero a -> NonZero a -> Ordering
Ord, forall a b. a -> NonZero b -> NonZero a
forall a b. (a -> b) -> NonZero a -> NonZero b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> NonZero b -> NonZero a
$c<$ :: forall a b. a -> NonZero b -> NonZero a
fmap :: forall a b. (a -> b) -> NonZero a -> NonZero b
$cfmap :: forall a b. (a -> b) -> NonZero a -> NonZero b
Functor, forall a. Eq a => a -> NonZero a -> Bool
forall a. Num a => NonZero a -> a
forall a. Ord a => NonZero a -> a
forall m. Monoid m => NonZero m -> m
forall a. NonZero a -> Bool
forall a. NonZero a -> Depth
forall a. NonZero a -> [a]
forall a. (a -> a -> a) -> NonZero a -> a
forall m a. Monoid m => (a -> m) -> NonZero a -> m
forall b a. (b -> a -> b) -> b -> NonZero a -> b
forall a b. (a -> b -> b) -> b -> NonZero a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Depth)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => NonZero a -> a
$cproduct :: forall a. Num a => NonZero a -> a
sum :: forall a. Num a => NonZero a -> a
$csum :: forall a. Num a => NonZero a -> a
minimum :: forall a. Ord a => NonZero a -> a
$cminimum :: forall a. Ord a => NonZero a -> a
maximum :: forall a. Ord a => NonZero a -> a
$cmaximum :: forall a. Ord a => NonZero a -> a
elem :: forall a. Eq a => a -> NonZero a -> Bool
$celem :: forall a. Eq a => a -> NonZero a -> Bool
length :: forall a. NonZero a -> Depth
$clength :: forall a. NonZero a -> Depth
null :: forall a. NonZero a -> Bool
$cnull :: forall a. NonZero a -> Bool
toList :: forall a. NonZero a -> [a]
$ctoList :: forall a. NonZero a -> [a]
foldl1 :: forall a. (a -> a -> a) -> NonZero a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> NonZero a -> a
foldr1 :: forall a. (a -> a -> a) -> NonZero a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> NonZero a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> NonZero a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> NonZero a -> b
foldl :: forall b a. (b -> a -> b) -> b -> NonZero a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> NonZero a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> NonZero a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> NonZero a -> b
foldr :: forall a b. (a -> b -> b) -> b -> NonZero a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> NonZero a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> NonZero a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> NonZero a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> NonZero a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> NonZero a -> m
fold :: forall m. Monoid m => NonZero m -> m
$cfold :: forall m. Monoid m => NonZero m -> m
Foldable, Functor NonZero
Foldable NonZero
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => NonZero (m a) -> m (NonZero a)
forall (f :: * -> *) a.
Applicative f =>
NonZero (f a) -> f (NonZero a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonZero a -> m (NonZero b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonZero a -> f (NonZero b)
sequence :: forall (m :: * -> *) a. Monad m => NonZero (m a) -> m (NonZero a)
$csequence :: forall (m :: * -> *) a. Monad m => NonZero (m a) -> m (NonZero a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonZero a -> m (NonZero b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonZero a -> m (NonZero b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
NonZero (f a) -> f (NonZero a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
NonZero (f a) -> f (NonZero a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonZero a -> f (NonZero b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonZero a -> f (NonZero b)
Traversable)

instance Real a => Real (NonZero a) where
  toRational :: NonZero a -> Rational
toRational (NonZero a
x) = forall a. Real a => a -> Rational
toRational a
x

instance (Eq a, Num a, Bounded a) => Bounded (NonZero a) where
  minBound :: NonZero a
minBound = let x :: a
x = forall a. Bounded a => a
minBound in forall a. a -> NonZero a
NonZero (if a
x forall a. Eq a => a -> a -> Bool
== a
0 then  a
1 else a
x)
  maxBound :: NonZero a
maxBound = let x :: a
x = forall a. Bounded a => a
maxBound in forall a. a -> NonZero a
NonZero (if a
x forall a. Eq a => a -> a -> Bool
== a
0 then -a
1 else a
x)

instance Enum a => Enum (NonZero a) where
  toEnum :: Depth -> NonZero a
toEnum Depth
x = forall a. a -> NonZero a
NonZero (forall a. Enum a => Depth -> a
toEnum Depth
x)
  fromEnum :: NonZero a -> Depth
fromEnum (NonZero a
x) = forall a. Enum a => a -> Depth
fromEnum a
x

instance Num a => Num (NonZero a) where
  NonZero a
x + :: NonZero a -> NonZero a -> NonZero a
+ NonZero a
y = forall a. a -> NonZero a
NonZero (a
x forall a. Num a => a -> a -> a
+ a
y)
  NonZero a
x * :: NonZero a -> NonZero a -> NonZero a
* NonZero a
y = forall a. a -> NonZero a
NonZero (a
x forall a. Num a => a -> a -> a
* a
y)
  negate :: NonZero a -> NonZero a
negate (NonZero a
x) = forall a. a -> NonZero a
NonZero (forall a. Num a => a -> a
negate a
x)
  abs :: NonZero a -> NonZero a
abs (NonZero a
x) = forall a. a -> NonZero a
NonZero (forall a. Num a => a -> a
abs a
x)
  signum :: NonZero a -> NonZero a
signum (NonZero a
x) = forall a. a -> NonZero a
NonZero (forall a. Num a => a -> a
signum a
x)
  fromInteger :: Integer -> NonZero a
fromInteger Integer
x = forall a. a -> NonZero a
NonZero (forall a. Num a => Integer -> a
fromInteger Integer
x)

instance Integral a => Integral (NonZero a) where
  quotRem :: NonZero a -> NonZero a -> (NonZero a, NonZero a)
quotRem (NonZero a
x) (NonZero a
y) = (forall a. a -> NonZero a
NonZero a
q, forall a. a -> NonZero a
NonZero a
r)
    where
      (a
q, a
r) = a
x forall a. Integral a => a -> a -> (a, a)
`quotRem` a
y
  toInteger :: NonZero a -> Integer
toInteger (NonZero a
x) = forall a. Integral a => a -> Integer
toInteger a
x

instance (Num a, Ord a, Serial m a) => Serial m (NonZero a) where
  series :: Series m (NonZero a)
series = forall a. a -> NonZero a
NonZero forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. Serial m a => Series m a
series forall (m :: * -> *) a. Series m a -> (a -> Bool) -> Series m a
`suchThat` (forall a. Eq a => a -> a -> Bool
/= a
0)

instance Show a => Show (NonZero a) where
  showsPrec :: Depth -> NonZero a -> ShowS
showsPrec Depth
n (NonZero a
x) = forall a. Show a => Depth -> a -> ShowS
showsPrec Depth
n a
x

-- | 'NonEmpty' @xs@ guarantees that @xs@ is not null.
--
-- @since 1.1
newtype NonEmpty a = NonEmpty { forall a. NonEmpty a -> [a]
getNonEmpty :: [a] }

instance (Serial m a) => Serial m (NonEmpty a) where
  series :: Series m (NonEmpty a)
series = forall a. [a] -> NonEmpty a
NonEmpty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a b c.
(Serial m a, Serial m b) =>
(a -> b -> c) -> Series m c
cons2 (:)

instance Show a => Show (NonEmpty a) where
  showsPrec :: Depth -> NonEmpty a -> ShowS
showsPrec Depth
n (NonEmpty [a]
x) = forall a. Show a => Depth -> a -> ShowS
showsPrec Depth
n [a]
x

-- }}}

------------------------------
-- Foreign.C.Types
------------------------------
-- {{{

#if MIN_VERSION_base(4,5,0)
-- | @since 1.2.0
instance Monad m => Serial m CFloat where
  series :: Series m CFloat
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Float -> CFloat
CFloat
-- | @since 1.2.0
instance Monad m => CoSerial m CFloat where
  coseries :: forall b. Series m b -> Series m (CFloat -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Float -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CFloat
l -> case CFloat
l of CFloat Float
x -> Float -> b
f Float
x

-- | @since 1.2.0
instance Monad m => Serial m CDouble where
  series :: Series m CDouble
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Double -> CDouble
CDouble
-- | @since 1.2.0
instance Monad m => CoSerial m CDouble where
  coseries :: forall b. Series m b -> Series m (CDouble -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Double -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CDouble
l -> case CDouble
l of CDouble Double
x -> Double -> b
f Double
x

#if HASCBOOL
-- | @since 1.2.0
instance Monad m => Serial m CBool where
  series :: Series m CBool
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word8 -> CBool
CBool
-- | @since 1.2.0
instance Monad m => CoSerial m CBool where
  coseries :: forall b. Series m b -> Series m (CBool -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word8 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CBool
l -> case CBool
l of CBool Word8
x -> Word8 -> b
f Word8
x
#endif

-- | @since 1.2.0
instance Monad m => Serial m CChar where
  series :: Series m CChar
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int8 -> CChar
CChar
-- | @since 1.2.0
instance Monad m => CoSerial m CChar where
  coseries :: forall b. Series m b -> Series m (CChar -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int8 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CChar
l -> case CChar
l of CChar Int8
x -> Int8 -> b
f Int8
x

-- | @since 1.2.0
instance Monad m => Serial m CSChar where
  series :: Series m CSChar
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int8 -> CSChar
CSChar
-- | @since 1.2.0
instance Monad m => CoSerial m CSChar where
  coseries :: forall b. Series m b -> Series m (CSChar -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int8 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CSChar
l -> case CSChar
l of CSChar Int8
x -> Int8 -> b
f Int8
x

-- | @since 1.2.0
instance Monad m => Serial m CUChar where
  series :: Series m CUChar
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word8 -> CUChar
CUChar
-- | @since 1.2.0
instance Monad m => CoSerial m CUChar where
  coseries :: forall b. Series m b -> Series m (CUChar -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word8 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUChar
l -> case CUChar
l of CUChar Word8
x -> Word8 -> b
f Word8
x

-- | @since 1.2.0
instance Monad m => Serial m CShort where
  series :: Series m CShort
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int16 -> CShort
CShort
-- | @since 1.2.0
instance Monad m => CoSerial m CShort where
  coseries :: forall b. Series m b -> Series m (CShort -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int16 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CShort
l -> case CShort
l of CShort Int16
x -> Int16 -> b
f Int16
x

-- | @since 1.2.0
instance Monad m => Serial m CUShort where
  series :: Series m CUShort
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word16 -> CUShort
CUShort
-- | @since 1.2.0
instance Monad m => CoSerial m CUShort where
  coseries :: forall b. Series m b -> Series m (CUShort -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word16 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUShort
l -> case CUShort
l of CUShort Word16
x -> Word16 -> b
f Word16
x

-- | @since 1.2.0
instance Monad m => Serial m CInt where
  series :: Series m CInt
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int32 -> CInt
CInt
-- | @since 1.2.0
instance Monad m => CoSerial m CInt where
  coseries :: forall b. Series m b -> Series m (CInt -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int32 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CInt
l -> case CInt
l of CInt Int32
x -> Int32 -> b
f Int32
x

-- | @since 1.2.0
instance Monad m => Serial m CUInt where
  series :: Series m CUInt
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word32 -> CUInt
CUInt
-- | @since 1.2.0
instance Monad m => CoSerial m CUInt where
  coseries :: forall b. Series m b -> Series m (CUInt -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word32 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUInt
l -> case CUInt
l of CUInt Word32
x -> Word32 -> b
f Word32
x

-- | @since 1.2.0
instance Monad m => Serial m CLong where
  series :: Series m CLong
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CLong
CLong
-- | @since 1.2.0
instance Monad m => CoSerial m CLong where
  coseries :: forall b. Series m b -> Series m (CLong -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CLong
l -> case CLong
l of CLong Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CULong where
  series :: Series m CULong
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word64 -> CULong
CULong
-- | @since 1.2.0
instance Monad m => CoSerial m CULong where
  coseries :: forall b. Series m b -> Series m (CULong -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CULong
l -> case CULong
l of CULong Word64
x -> Word64 -> b
f Word64
x

-- | @since 1.2.0
instance Monad m => Serial m CPtrdiff where
  series :: Series m CPtrdiff
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CPtrdiff
CPtrdiff
-- | @since 1.2.0
instance Monad m => CoSerial m CPtrdiff where
  coseries :: forall b. Series m b -> Series m (CPtrdiff -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CPtrdiff
l -> case CPtrdiff
l of CPtrdiff Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CSize where
  series :: Series m CSize
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word64 -> CSize
CSize
-- | @since 1.2.0
instance Monad m => CoSerial m CSize where
  coseries :: forall b. Series m b -> Series m (CSize -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CSize
l -> case CSize
l of CSize Word64
x -> Word64 -> b
f Word64
x

-- | @since 1.2.0
instance Monad m => Serial m CWchar where
  series :: Series m CWchar
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int32 -> CWchar
CWchar
-- | @since 1.2.0
instance Monad m => CoSerial m CWchar where
  coseries :: forall b. Series m b -> Series m (CWchar -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int32 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CWchar
l -> case CWchar
l of CWchar Int32
x -> Int32 -> b
f Int32
x

-- | @since 1.2.0
instance Monad m => Serial m CSigAtomic where
  series :: Series m CSigAtomic
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int32 -> CSigAtomic
CSigAtomic
-- | @since 1.2.0
instance Monad m => CoSerial m CSigAtomic where
  coseries :: forall b. Series m b -> Series m (CSigAtomic -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int32 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CSigAtomic
l -> case CSigAtomic
l of CSigAtomic Int32
x -> Int32 -> b
f Int32
x

-- | @since 1.2.0
instance Monad m => Serial m CLLong where
  series :: Series m CLLong
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CLLong
CLLong
-- | @since 1.2.0
instance Monad m => CoSerial m CLLong where
  coseries :: forall b. Series m b -> Series m (CLLong -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CLLong
l -> case CLLong
l of CLLong Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CULLong where
  series :: Series m CULLong
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word64 -> CULLong
CULLong
-- | @since 1.2.0
instance Monad m => CoSerial m CULLong where
  coseries :: forall b. Series m b -> Series m (CULLong -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CULLong
l -> case CULLong
l of CULLong Word64
x -> Word64 -> b
f Word64
x

-- | @since 1.2.0
instance Monad m => Serial m CIntPtr where
  series :: Series m CIntPtr
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CIntPtr
CIntPtr
-- | @since 1.2.0
instance Monad m => CoSerial m CIntPtr where
  coseries :: forall b. Series m b -> Series m (CIntPtr -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CIntPtr
l -> case CIntPtr
l of CIntPtr Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CUIntPtr where
  series :: Series m CUIntPtr
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word64 -> CUIntPtr
CUIntPtr
-- | @since 1.2.0
instance Monad m => CoSerial m CUIntPtr where
  coseries :: forall b. Series m b -> Series m (CUIntPtr -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUIntPtr
l -> case CUIntPtr
l of CUIntPtr Word64
x -> Word64 -> b
f Word64
x

-- | @since 1.2.0
instance Monad m => Serial m CIntMax where
  series :: Series m CIntMax
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CIntMax
CIntMax
-- | @since 1.2.0
instance Monad m => CoSerial m CIntMax where
  coseries :: forall b. Series m b -> Series m (CIntMax -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CIntMax
l -> case CIntMax
l of CIntMax Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CUIntMax where
  series :: Series m CUIntMax
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word64 -> CUIntMax
CUIntMax
-- | @since 1.2.0
instance Monad m => CoSerial m CUIntMax where
  coseries :: forall b. Series m b -> Series m (CUIntMax -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUIntMax
l -> case CUIntMax
l of CUIntMax Word64
x -> Word64 -> b
f Word64
x

-- | @since 1.2.0
instance Monad m => Serial m CClock where
  series :: Series m CClock
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CClock
CClock
-- | @since 1.2.0
instance Monad m => CoSerial m CClock where
  coseries :: forall b. Series m b -> Series m (CClock -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CClock
l -> case CClock
l of CClock Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CTime where
  series :: Series m CTime
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CTime
CTime
-- | @since 1.2.0
instance Monad m => CoSerial m CTime where
  coseries :: forall b. Series m b -> Series m (CTime -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CTime
l -> case CTime
l of CTime Int64
x -> Int64 -> b
f Int64
x

-- | @since 1.2.0
instance Monad m => Serial m CUSeconds where
  series :: Series m CUSeconds
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Word32 -> CUSeconds
CUSeconds
-- | @since 1.2.0
instance Monad m => CoSerial m CUSeconds where
  coseries :: forall b. Series m b -> Series m (CUSeconds -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Word32 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CUSeconds
l -> case CUSeconds
l of CUSeconds Word32
x -> Word32 -> b
f Word32
x

-- | @since 1.2.0
instance Monad m => Serial m CSUSeconds where
  series :: Series m CSUSeconds
series = forall (m :: * -> *) a b. Serial m a => (a -> b) -> Series m b
newtypeCons Int64 -> CSUSeconds
CSUSeconds
-- | @since 1.2.0
instance Monad m => CoSerial m CSUSeconds where
  coseries :: forall b. Series m b -> Series m (CSUSeconds -> b)
coseries Series m b
rs = forall (m :: * -> *) a b.
CoSerial m a =>
Series m b -> Series m (a -> b)
newtypeAlts Series m b
rs forall (m :: * -> *) a b. MonadLogic m => m a -> (a -> m b) -> m b
>>- \Int64 -> b
f -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ \CSUSeconds
l -> case CSUSeconds
l of CSUSeconds Int64
x -> Int64 -> b
f Int64
x
#endif

-- }}}