config-value-0.8.3: Simple, layout-based value language similar to YAML or JSON

Copyright | (c) Eric Mertens 2019
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | Safe
Language | Haskell2010

Config.Number

Description

This module provides a representation of numbers in scientific notation.

Synopsis

- data Number = MkNumber {
  - numberRadix :: !Radix
  - numberCoefficient :: !Rational
  }
- data Radix
  - = Radix2
  - | Radix8
  - | Radix10 !Integer
  - | Radix16 !Integer
- radixToInt :: Radix -> Int
- numberToRational :: Number -> Rational
- numberToInteger :: Number -> Maybe Integer
- integerToNumber :: Integer -> Number
- rationalToNumber :: Rational -> Number

# Documentation

data Number Source #

Numbers are represented as base, coefficient, and exponent.

The most convenient way to get numbers into and out of this form is to use one of: `numberToRational`, `numberToInteger`, `rationalToNumber`, or `integerToNumber`.

This representation is explicit about the radix and exponent used to facilitate better pretty-printing. By using explicit exponents extremely large numbers can be represented compactly. Consider that it is easy to write `1e100000000` which would use a significant amount of memory if realized as an `Integer`. This representation allows concerned programs to check bounds before converting to a representation like `Integer`.

Constructors

MkNumber |

Fields

- numberRadix :: !Radix
- numberCoefficient :: !Rational

#### Instances

Instances details

Data Number Source # |

Instance details

Defined in Config.Number

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Number -> c Number Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Number Source #

toConstr :: Number -> Constr Source #

dataTypeOf :: Number -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Number) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Number) Source #

gmapT :: (forall b. Data b => b -> b) -> Number -> Number Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Number -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Number -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Number -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Number -> m Number Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Number -> m Number Source #

Generic Number Source # |

Instance details

Defined in Config.Number

Associated Types

type Rep Number |

Instance details

Defined in Config.Number

type Rep Number = D1 ('MetaData "Number" "Config.Number" "config-value-0.8.3-IpF6E1RCTYnALBsLrK00Yp" 'False) (C1 ('MetaCons "MkNumber" 'PrefixI 'True) (S1 ('MetaSel ('Just "numberRadix") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Radix) :*: S1 ('MetaSel ('Just "numberCoefficient") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Rational)))

Methods

from :: Number -> Rep Number x Source #

to :: Rep Number x -> Number Source #

Read Number Source # |
Instance details Defined in Config.Number Methods readsPrec :: Int -> ReadS Number Source # readList :: ReadS [Number] Source # readPrec :: ReadPrec Number Source # readListPrec :: ReadPrec [Number] Source #
Show Number Source # |
Instance details Defined in Config.Number Methods showsPrec :: Int -> Number -> ShowS Source # show :: Number -> String Source # showList :: [Number] -> ShowS Source #
Eq Number Source # |
Instance details Defined in Config.Number Methods (==) :: Number -> Number -> Bool Source # (/=) :: Number -> Number -> Bool Source #
Ord Number Source # |
Instance details Defined in Config.Number Methods compare :: Number -> Number -> Ordering Source # (<) :: Number -> Number -> Bool Source # (<=) :: Number -> Number -> Bool Source # (>) :: Number -> Number -> Bool Source # (>=) :: Number -> Number -> Bool Source # max :: Number -> Number -> Number Source # min :: Number -> Number -> Number Source #
type Rep Number Source # |

Instance details

Defined in Config.Number

type Rep Number = D1 ('MetaData "Number" "Config.Number" "config-value-0.8.3-IpF6E1RCTYnALBsLrK00Yp" 'False) (C1 ('MetaCons "MkNumber" 'PrefixI 'True) (S1 ('MetaSel ('Just "numberRadix") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Radix) :*: S1 ('MetaSel ('Just "numberCoefficient") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Rational)))

data Radix Source #

Radix used for a number. Some radix modes support an exponent.

Constructors

Radix2 | binary, base 2
Radix8 | octal, base 8
Radix10 !Integer | decimal, base 10, exponent base 10
Radix16 !Integer | hexdecimal, base 16, exponent base 2

#### Instances

Instances details

Data Radix Source # |

Instance details

Defined in Config.Number

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Radix -> c Radix Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Radix Source #

toConstr :: Radix -> Constr Source #

dataTypeOf :: Radix -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Radix) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Radix) Source #

gmapT :: (forall b. Data b => b -> b) -> Radix -> Radix Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Radix -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Radix -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Radix -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Radix -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Radix -> m Radix Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Radix -> m Radix Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Radix -> m Radix Source #

Generic Radix Source # |

Instance details

Defined in Config.Number

Associated Types

type Rep Radix |

Instance details

Defined in Config.Number

type Rep Radix = D1 ('MetaData "Radix" "Config.Number" "config-value-0.8.3-IpF6E1RCTYnALBsLrK00Yp" 'False) ((C1 ('MetaCons "Radix2" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Radix8" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Radix10" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Radix16" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer))))

Methods

from :: Radix -> Rep Radix x Source #

to :: Rep Radix x -> Radix Source #

Read Radix Source # |
Instance details Defined in Config.Number Methods readsPrec :: Int -> ReadS Radix Source # readList :: ReadS [Radix] Source # readPrec :: ReadPrec Radix Source # readListPrec :: ReadPrec [Radix] Source #
Show Radix Source # |
Instance details Defined in Config.Number Methods showsPrec :: Int -> Radix -> ShowS Source # show :: Radix -> String Source # showList :: [Radix] -> ShowS Source #
Eq Radix Source # |
Instance details Defined in Config.Number Methods (==) :: Radix -> Radix -> Bool Source # (/=) :: Radix -> Radix -> Bool Source #
Ord Radix Source # |
Instance details Defined in Config.Number Methods compare :: Radix -> Radix -> Ordering Source # (<) :: Radix -> Radix -> Bool Source # (<=) :: Radix -> Radix -> Bool Source # (>) :: Radix -> Radix -> Bool Source # (>=) :: Radix -> Radix -> Bool Source # max :: Radix -> Radix -> Radix Source # min :: Radix -> Radix -> Radix Source #
type Rep Radix Source # |

Instance details

Defined in Config.Number

type Rep Radix = D1 ('MetaData "Radix" "Config.Number" "config-value-0.8.3-IpF6E1RCTYnALBsLrK00Yp" 'False) ((C1 ('MetaCons "Radix2" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Radix8" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Radix10" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer)) :+: C1 ('MetaCons "Radix16" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Integer))))

radixToInt :: Radix -> Int Source #

Returns the radix as an integer ignoring any exponent.

numberToRational :: Number -> Rational Source #

Convert a number to a `Rational`. Warning: This can use a lot of memory in the case of very large exponent parts.

numberToInteger :: Number -> Maybe Integer Source #

Convert a number to a `Integer`. Warning: This can use a lot of memory in the case of very large exponent parts.

integerToNumber :: Integer -> Number Source #

`Integer` to a radix 10 `Number` with no exponent

rationalToNumber :: Rational -> Number Source #

`Rational` to a radix 10 `Number` with no exponent