decimal-literals-0.1.0.0: Preprocessing decimal literals more or less as they are (instead of via fractions)

Copyright(c) Justus Sagemüller 2017
LicenseGPL v3
Maintainer(@) jsagemue $ uni-koeln.de
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Numeric.Literals.Decimal

Contents

Description

 

Synopsis

Documentation

data FractionalLit Source #

A type whose Fractional instance gives a somewhat reliable indication whether a value was actually defined as an integer or a ratio, or as a decimal-fraction literal. This is useful to know for a type that supports both exact fraction values and more floating-point-like / physical values; it allows avoiding issues like 0.524 showing up as 589971551185535/1125899906842624, or conversely 7/23 as 0.30434782608695654. Both of these scenarios are quite awkward.

Instances

Eq FractionalLit Source # 
Fractional FractionalLit Source #

Despite the name, fromRational should not be used to promote a Rational value to FractionalLit, because that method contains the heuristic which interprets decimal/scientific literals (which in Haskell are, perhaps unfortunately, always desugared through fromRational). Use / or :% instead, to define exact-ratio values.

Num FractionalLit Source # 
Show FractionalLit Source # 

Methods

showsPrec :: Int -> FractionalLit -> ShowS

show :: FractionalLit -> String

showList :: [FractionalLit] -> ShowS

pattern (:%) :: Integer -> Integer -> FractionalLit Source #

Construct an exact fraction. The values behave like Rational, until combined – e.g. added – with a Scientific value (which has an implicit measurement-uncertainty, and that carries over to the result).

pattern Scientific :: Int -> [B₁₀Digit] -> Int -> FractionalLit Source #

Construct a scientific number of the form m.n * 10^e, where m and e are integers and n is a list of digits after the decimal point. The result is considered to be only exact up to the precision indicated by the number of digits. I.e. Scientific 2 [4,8,3] (-4) basically means 2.483×10⁻⁴ ± 10⁻⁷,

The Fractional instance allows these values to be written in the standard 2.483e-4 notation. Note that this cannot completely reconstruct the written form, e.g. 12.483e-4 will actually show up as Scientific 1 [2,4,8,3] (-3). Leading and trailing zeroes are always ignored.

Auxiliary