-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Generalized booleans and numbers
--   
--   Some classes for generalized boolean operations. Starting with 0.1.0,
--   this package uses type families. Up to version 0.0.2, it used MPTCs
--   with functional dependencies. My thanks to Andy Gill for suggesting
--   & helping with the change. Thanks also to Alex Horsman for
--   Data.Boolean.Overload and to Jan Bracker for Data.Boolean.Numbers.
--   
--   Copyright 2009-2013 Conal Elliott; BSD3 license.
@package Boolean
@version 0.2.4

-- | Some classes for generalized boolean operations.
--   
--   In this design, for if-then-else, equality and inequality tests, the
--   boolean type depends on the value type.
--   
--   I also tried using a unary type constructor class. The class doesn't
--   work for regular booleans, so generality is lost. Also, we'd probably
--   have to wire class constraints in like: (==*) :: Eq a => f Bool
--   -> f a -> f a -> f a, which disallows situations needing
--   additional constraints, e.g., Show.
--   
--   Starting with 0.1.0, this package uses type families. Up to version
--   0.0.2, it used MPTCs with functional dependencies. My thanks to Andy
--   Gill for suggesting & helping with the change.
module Data.Boolean

-- | Generalized boolean class
class Boolean b
true :: Boolean b => b
false :: Boolean b => b
notB :: Boolean b => b -> b
(&&*) :: Boolean b => b -> b -> b
(||*) :: Boolean b => b -> b -> b
infixr 3 &&*
infixr 2 ||*

-- | BooleanOf computed the boolean analog of a specific type.
type family BooleanOf a

-- | Types with conditionals
class Boolean BooleanOf a => IfB a
ifB :: (IfB a, bool ~ BooleanOf a) => bool -> a -> a -> a

-- | Expression-lifted conditional with condition last
boolean :: (IfB a, bool ~ BooleanOf a) => a -> a -> bool -> a

-- | Point-wise conditional
cond :: (Applicative f, IfB a, bool ~ BooleanOf a) => f bool -> f a -> f a -> f a

-- | Generalized cropping, filling in mempty where the test yields
--   false.
crop :: (Applicative f, Monoid (f a), IfB a, bool ~ BooleanOf a) => f bool -> f a -> f a

-- | Types with equality. Minimum definition: (==*).
class Boolean BooleanOf a => EqB a
(==*) :: (EqB a, bool ~ BooleanOf a) => a -> a -> bool
(/=*) :: (EqB a, bool ~ BooleanOf a) => a -> a -> bool
infix 4 ==*
infix 4 /=*

-- | Types with inequality. Minimum definition: (<*).
class Boolean BooleanOf a => OrdB a
(<*) :: (OrdB a, bool ~ BooleanOf a) => a -> a -> bool
(<=*) :: (OrdB a, bool ~ BooleanOf a) => a -> a -> bool
(>*) :: (OrdB a, bool ~ BooleanOf a) => a -> a -> bool
(>=*) :: (OrdB a, bool ~ BooleanOf a) => a -> a -> bool
infix 4 <*
infix 4 <=*
infix 4 >*
infix 4 >=*

-- | Variant of min using ifB and (<=*)
minB :: (IfB a, OrdB a) => a -> a -> a

-- | Variant of max using ifB and (>=*)
maxB :: (IfB a, OrdB a) => a -> a -> a

-- | Variant of min and max using ifB and
--   (<=*)
sort2B :: (IfB a, OrdB a) => (a, a) -> (a, a)

-- | A generalized replacement for guards and chained ifs.
guardedB :: (IfB b, bool ~ BooleanOf b) => bool -> [(bool, b)] -> b -> b

-- | A generalized version of a case like control structure.
caseB :: (IfB b, bool ~ BooleanOf b) => a -> [(a -> bool, b)] -> b -> b
instance Data.Boolean.Boolean GHC.Types.Bool
instance Data.Boolean.Boolean bool => Data.Boolean.Boolean (z -> bool)
instance Data.Boolean.EqB GHC.Types.Bool
instance Data.Boolean.EqB GHC.Types.Char
instance Data.Boolean.EqB GHC.Types.Double
instance Data.Boolean.EqB a => Data.Boolean.EqB (z -> a)
instance Data.Boolean.EqB GHC.Types.Float
instance Data.Boolean.EqB GHC.Types.Int
instance Data.Boolean.EqB GHC.Num.Integer.Integer
instance Data.Boolean.IfB GHC.Types.Bool
instance Data.Boolean.IfB GHC.Types.Char
instance Data.Boolean.IfB GHC.Types.Double
instance Data.Boolean.IfB a => Data.Boolean.IfB (z -> a)
instance Data.Boolean.IfB GHC.Types.Float
instance Data.Boolean.IfB GHC.Types.Int
instance Data.Boolean.IfB GHC.Num.Integer.Integer
instance (Data.Boolean.Boolean (Data.Boolean.BooleanOf a), Data.Boolean.BooleanOf a GHC.Types.~ GHC.Types.Bool) => Data.Boolean.IfB [a]
instance (bool GHC.Types.~ Data.Boolean.BooleanOf p, bool GHC.Types.~ Data.Boolean.BooleanOf q, Data.Boolean.IfB p, Data.Boolean.IfB q) => Data.Boolean.IfB (p, q)
instance (bool GHC.Types.~ Data.Boolean.BooleanOf p, bool GHC.Types.~ Data.Boolean.BooleanOf q, bool GHC.Types.~ Data.Boolean.BooleanOf r, Data.Boolean.IfB p, Data.Boolean.IfB q, Data.Boolean.IfB r) => Data.Boolean.IfB (p, q, r)
instance (bool GHC.Types.~ Data.Boolean.BooleanOf p, bool GHC.Types.~ Data.Boolean.BooleanOf q, bool GHC.Types.~ Data.Boolean.BooleanOf r, bool GHC.Types.~ Data.Boolean.BooleanOf s, Data.Boolean.IfB p, Data.Boolean.IfB q, Data.Boolean.IfB r, Data.Boolean.IfB s) => Data.Boolean.IfB (p, q, r, s)
instance Data.Boolean.OrdB GHC.Types.Bool
instance Data.Boolean.OrdB GHC.Types.Char
instance Data.Boolean.OrdB GHC.Types.Double
instance Data.Boolean.OrdB a => Data.Boolean.OrdB (z -> a)
instance Data.Boolean.OrdB GHC.Types.Float
instance Data.Boolean.OrdB GHC.Types.Int
instance Data.Boolean.OrdB GHC.Num.Integer.Integer

-- | A generalized version of the class hirarchy for numbers. All functions
--   that would break a potential deep embedding are removed or generalized
--   to support deep embeddings.
--   
--   The class hierarchy for numeric types keeps as close as possible to
--   the Prelude hierarchy. A great part of the default
--   implementation and comments are copied and adopted from
--   Prelude.
module Data.Boolean.Numbers

-- | An extension of Num that supplies the integer type of a given
--   number type and a way to create that number from the integer.
class Num a => NumB a where {
    
    -- | The accociated integer type of the number.
    type IntegerOf a;
}

-- | Construct the number from the associated integer.
fromIntegerB :: NumB a => IntegerOf a -> a

-- | A deep embedded version of Integral. Integral numbers,
--   supporting integer division.
--   
--   Minimal complete definition is either quotRem and divMod
--   or the other four functions. Besides that toIntegerB always has
--   to be implemented.
class (NumB a, OrdB a) => IntegralB a

-- | Integer division truncated towards zero.
quot :: IntegralB a => a -> a -> a

-- | Integer reminder, satisfying: (x quot y) * y + (x
--   rem y) == x
rem :: IntegralB a => a -> a -> a

-- | Integer division truncated toward negative infinity.
div :: IntegralB a => a -> a -> a

-- | Integer modulus, satisfying: (x div y) * y + (x mod
--   y) == x
mod :: IntegralB a => a -> a -> a

-- | Simultaneous quot and rem.
quotRem :: IntegralB a => a -> a -> (a, a)

-- | Simultaneous div and mod.
divMod :: IntegralB a => a -> a -> (a, a)

-- | Create a integer from this integral.
toIntegerB :: IntegralB a => a -> IntegerOf a

-- | Deep embedded version of RealFloat. Extracting components of
--   fractions.
--   
--   Minimal complete definition: properFraction, round,
--   floor and ceiling.
class (NumB a, OrdB a, Fractional a) => RealFracB a

-- | The function properFraction takes a real fractional number
--   x and returns a pair (n,f) such that x =
--   n+f, and:
--   
--   
--   
- n is an integral number with the same sign as x;
--   and
--   
- f is a fraction with the same type and sign as
--   x, and with absolute value less than 1.
--   
--   
--   The default definitions of the ceiling, floor,
--   truncate and round functions are in terms of
--   properFraction.
properFraction :: (RealFracB a, IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a)

-- | truncate x returns the integer nearest x
--   between zero and x
truncate :: (RealFracB a, IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b

-- | round x returns the nearest integer to x; the
--   even integer if x is equidistant between two integers
round :: (RealFracB a, IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b

-- | ceiling x returns the least integer not less than
--   x
ceiling :: (RealFracB a, IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b

-- | floor x returns the greatest integer not greater than
--   x.
floor :: (RealFracB a, IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b

-- | Deep embedded version of RealFloat. Efficient,
--   machine-independent access to the components of a floating-point
--   number.
--   
--   A complete definition has to define all functions.
class (Boolean BooleanOf a, RealFracB a, Floating a) => RealFloatB a

-- | true if the argument is an IEEE "not-a-number" (NaN) value.
isNaN :: RealFloatB a => a -> BooleanOf a

-- | true if the argument is an IEEE infinity or negative infinity.
isInfinite :: RealFloatB a => a -> BooleanOf a

-- | true if the argument is an IEEE negative zero.
isNegativeZero :: RealFloatB a => a -> BooleanOf a

-- | true if the argument is an IEEE floating point number.
isIEEE :: RealFloatB a => a -> BooleanOf a

-- | a version of arctangent taking two real floating-point arguments. For
--   real floating x and y, atan2 y x
--   computes the angle (from the positive x-axis) of the vector from the
--   origin to the point (x,y). atan2 y x returns
--   a value in the range [-pi, pi]. It follows the
--   Common Lisp semantics for the origin when signed zeroes are supported.
--   atan2 y 1, with y in a type that is
--   RealFloatB, should return the same value as atan
--   y.
atan2 :: RealFloatB a => a -> a -> a

-- | Variant of even for generalized booleans.
evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a

-- | Variant of odd for generalized booleans.
oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a

-- | Variant of fromIntegral for generalized booleans.
fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b
instance Data.Boolean.Numbers.IntegralB GHC.Types.Int
instance Data.Boolean.Numbers.IntegralB GHC.Num.Integer.Integer
instance Data.Boolean.Numbers.NumB GHC.Types.Double
instance Data.Boolean.Numbers.NumB GHC.Types.Float
instance Data.Boolean.Numbers.NumB GHC.Types.Int
instance Data.Boolean.Numbers.NumB GHC.Num.Integer.Integer
instance Data.Boolean.Numbers.RealFloatB GHC.Types.Double
instance Data.Boolean.Numbers.RealFloatB GHC.Types.Float
instance Data.Boolean.Numbers.RealFracB GHC.Types.Double
instance Data.Boolean.Numbers.RealFracB GHC.Types.Float

-- | Definitions of Prelude function names in terms of their corresponding
--   Data.Boolean generalised implementation. This can then be used as part
--   of a partial or complete Prelude replacement.
--   
--   Also exports ifThenElse for use with RebindableSyntax.
module Data.Boolean.Overload
(&&) :: Boolean a => a -> a -> a
infixr 3 &&
(||) :: Boolean a => a -> a -> a
infixr 2 ||
not :: Boolean a => a -> a
ifThenElse :: IfB a => BooleanOf a -> a -> a -> a
(==) :: EqB a => a -> a -> BooleanOf a
infix 4 ==
(/=) :: EqB a => a -> a -> BooleanOf a
infix 4 /=
(<) :: OrdB a => a -> a -> BooleanOf a
infix 4 <
(>) :: OrdB a => a -> a -> BooleanOf a
infix 4 >
(<=) :: OrdB a => a -> a -> BooleanOf a
infix 4 <=
(>=) :: OrdB a => a -> a -> BooleanOf a
infix 4 >=
min :: (IfB a, OrdB a) => a -> a -> a
max :: (IfB a, OrdB a) => a -> a -> a
