Boolean-0.2.4: Generalized booleans and numbers

Copyright | (c) Jan Bracker 2013
License | BSD3
Maintainer | jbra@informatik.uni-kiel.de
Stability | experimental
Safe Haskell | Safe-Inferred
Language | Haskell98

Data.Boolean.Numbers

Description

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`.

Synopsis

- class Num a => NumB a where
  - type IntegerOf a
  - fromIntegerB :: IntegerOf a -> a
- class (NumB a, OrdB a) => IntegralB a where
  - quot :: a -> a -> a
  - rem :: a -> a -> a
  - div :: a -> a -> a
  - mod :: a -> a -> a
  - quotRem :: a -> a -> (a, a)
  - divMod :: a -> a -> (a, a)
  - toIntegerB :: a -> IntegerOf a
- class (NumB a, OrdB a, Fractional a) => RealFracB a where
  - properFraction :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a)
  - truncate :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
  - round :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
  - ceiling :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
  - floor :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b
- class (Boolean (BooleanOf a), RealFracB a, Floating a) => RealFloatB a where
  - isNaN :: a -> BooleanOf a
  - isInfinite :: a -> BooleanOf a
  - isNegativeZero :: a -> BooleanOf a
  - isIEEE :: a -> BooleanOf a
  - atan2 :: a -> a -> a
- evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a
- oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a
- fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b

# Documentation

class Num a => NumB a where Source #

An extension of `Num` that supplies the integer type of a given number type and a way to create that number from the integer.

Associated Types

type IntegerOf a Source #

The accociated integer type of the number.

Methods

fromIntegerB :: IntegerOf a -> a Source #

Construct the number from the associated integer.

#### Instances

Instances details

NumB Integer Source # |

Instance details

Defined in Data.Boolean.Numbers

Associated Types

type IntegerOf Integer |
Instance details Defined in Data.Boolean.Numbers type IntegerOf Integer = Integer

Methods

fromIntegerB :: IntegerOf Integer -> Integer Source #

NumB Double Source # |

Instance details

Defined in Data.Boolean.Numbers

Associated Types

type IntegerOf Double |
Instance details Defined in Data.Boolean.Numbers type IntegerOf Double = Integer

Methods

fromIntegerB :: IntegerOf Double -> Double Source #

NumB Float Source # |

Instance details

Defined in Data.Boolean.Numbers

Associated Types

type IntegerOf Float |
Instance details Defined in Data.Boolean.Numbers type IntegerOf Float = Integer

Methods

fromIntegerB :: IntegerOf Float -> Float Source #

NumB Int Source # |

Instance details

Defined in Data.Boolean.Numbers

Associated Types

type IntegerOf Int |
Instance details Defined in Data.Boolean.Numbers type IntegerOf Int = Integer

Methods

fromIntegerB :: IntegerOf Int -> Int Source #

class (NumB a, OrdB a) => IntegralB a where Source #

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.

Minimal complete definition

toIntegerB

Methods

quot :: a -> a -> a Source #

Integer division truncated towards zero.

rem :: a -> a -> a Source #

Integer reminder, satisfying: `(x `quot` y) * y + (x `rem` y) == x`

div :: a -> a -> a Source #

Integer division truncated toward negative infinity.

mod :: a -> a -> a Source #

Integer modulus, satisfying: `(x `div` y) * y + (x `mod` y) == x`

quotRem :: a -> a -> (a, a) Source #

Simultaneous `quot` and `rem`.

divMod :: a -> a -> (a, a) Source #

Simultaneous `div` and `mod`.

toIntegerB :: a -> IntegerOf a Source #

Create a integer from this integral.

#### Instances

Instances details

IntegralB Integer Source # |

Instance details

Defined in Data.Boolean.Numbers

Methods

quot :: Integer -> Integer -> Integer Source #

rem :: Integer -> Integer -> Integer Source #

div :: Integer -> Integer -> Integer Source #

mod :: Integer -> Integer -> Integer Source #

quotRem :: Integer -> Integer -> (Integer, Integer) Source #

divMod :: Integer -> Integer -> (Integer, Integer) Source #

toIntegerB :: Integer -> IntegerOf Integer Source #

IntegralB Int Source # |
Instance details Defined in Data.Boolean.Numbers Methods quot :: Int -> Int -> Int Source # rem :: Int -> Int -> Int Source # div :: Int -> Int -> Int Source # mod :: Int -> Int -> Int Source # quotRem :: Int -> Int -> (Int, Int) Source # divMod :: Int -> Int -> (Int, Int) Source # toIntegerB :: Int -> IntegerOf Int Source #

class (NumB a, OrdB a, Fractional a) => RealFracB a where Source #

Deep embedded version of `RealFloat`. Extracting components of fractions.

Minimal complete definition: `properFraction`, `round`, `floor` and `ceiling`.

Minimal complete definition

properFraction, round, ceiling, floor

Methods

properFraction :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> (b, a) Source #

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`.

truncate :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source #

``truncate` x` returns the integer nearest `x` between zero and `x`

round :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source #

``round` x` returns the nearest integer to `x`; the even integer if `x` is equidistant between two integers

ceiling :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source #

``ceiling` x` returns the least integer not less than `x`

floor :: (IntegerOf a ~ IntegerOf b, IntegralB b) => a -> b Source #

``floor` x` returns the greatest integer not greater than `x`.

#### Instances

Instances details

RealFracB Double Source # |

Instance details

Defined in Data.Boolean.Numbers

Methods

properFraction :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> (b, Double) Source #

truncate :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b Source #

round :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b Source #

ceiling :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b Source #

floor :: (IntegerOf Double ~ IntegerOf b, IntegralB b) => Double -> b Source #

RealFracB Float Source # |

Instance details

Defined in Data.Boolean.Numbers

Methods

properFraction :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> (b, Float) Source #

truncate :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b Source #

round :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b Source #

ceiling :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b Source #

floor :: (IntegerOf Float ~ IntegerOf b, IntegralB b) => Float -> b Source #

class (Boolean (BooleanOf a), RealFracB a, Floating a) => RealFloatB a where Source #

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.

Methods

isNaN :: a -> BooleanOf a Source #

`true` if the argument is an IEEE "not-a-number" (NaN) value.

isInfinite :: a -> BooleanOf a Source #

`true` if the argument is an IEEE infinity or negative infinity.

isNegativeZero :: a -> BooleanOf a Source #

`true` if the argument is an IEEE negative zero.

isIEEE :: a -> BooleanOf a Source #

`true` if the argument is an IEEE floating point number.

atan2 :: a -> a -> a Source #

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`.

#### Instances

Instances details

RealFloatB Double Source # |
Instance details Defined in Data.Boolean.Numbers Methods isNaN :: Double -> BooleanOf Double Source # isInfinite :: Double -> BooleanOf Double Source # isNegativeZero :: Double -> BooleanOf Double Source # isIEEE :: Double -> BooleanOf Double Source # atan2 :: Double -> Double -> Double Source #
RealFloatB Float Source # |
Instance details Defined in Data.Boolean.Numbers Methods isNaN :: Float -> BooleanOf Float Source # isInfinite :: Float -> BooleanOf Float Source # isNegativeZero :: Float -> BooleanOf Float Source # isIEEE :: Float -> BooleanOf Float Source # atan2 :: Float -> Float -> Float Source #

evenB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a Source #

Variant of `even` for generalized booleans.

oddB :: (IfB a, EqB a, IntegralB a) => a -> BooleanOf a Source #

Variant of `odd` for generalized booleans.

fromIntegralB :: (IntegerOf a ~ IntegerOf b, IntegralB a, NumB b) => a -> b Source #

Variant of `fromIntegral` for generalized booleans.