-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Business-quality formatting of numbers, dates, and other things -- @package formattable @version 0.1.1 -- | Formatting for numeric values. module Formattable.NumFormat -- | Primary function for formatting floating point numbers. formatNum :: Real a => NumFormat -> a -> Text -- | Primary function for formatting integrals. This was originally created -- to avoid depending on the double-conversion package which uses a C -- library and is therefore less portable. We're keeping this as a -- separate function because it should have the potential to be more -- efficient than the floating point version. formatIntegral :: Integral a => NumFormat -> a -> Text -- | Convenience wrapper for percentages that lets you easily control the -- number of decimal places. formatPct :: Real a => Int -> a -> Text -- | The main data structure with all the necessary information for -- formatting numbers. data NumFormat NumFormat :: Double -> Text -> Text -> Text -> Text -> NumStyle -> Maybe (Int, PrecisionType) -> NegativeStyle -> NumFormat -- | Units of measure to use in formatting the number. This is useful for -- things like percentages where you would use (units of 0.01) or -- financial statements (units of 1000 for example). _nfUnits :: NumFormat -> Double -- | A prefix to add to the number, commonly used for currency designation. _nfPrefix :: NumFormat -> Text -- | A suffix for the number. Percent, for example. _nfSuffix :: NumFormat -> Text -- | The character to use as thousands separator if applicable. _nfThouSep :: NumFormat -> Text -- | Character to use for the decimal separator. _nfDecSep :: NumFormat -> Text -- | The formatting style _nfStyle :: NumFormat -> NumStyle -- | Amount of precision to display _nfPrec :: NumFormat -> Maybe (Int, PrecisionType) -- | Styles for negative numbers _nfNegStyle :: NumFormat -> NegativeStyle -- | Data structure describing available styles of number formatting. data NumStyle -- | Format with scientific notation Exponent :: NumStyle -- | Format with standard decimal notation Fixed :: NumStyle -- | The aruments a and b define bounds. If the absolute value of the -- number is in the interval [10 ^ a, 10 ^ b], then it uses the Fixed -- style. If the number is outside this interval, then use the Exponent -- style. SmartExponent :: Int -> Int -> NumStyle -- | Adds the symbol for the closest smaller SI prefix as the suffix to the -- formatted number. This suffix appears before any other suffix you -- designate. SIStyle :: NumStyle -- | Like SIStyle but only applies the SI prefix if the number to be -- formatted falls within the range [a,b] given by the SmartSI arguments. SmartSI :: Double -> Double -> NumStyle -- | A reasonable default value for NumStyle. autoStyle :: NumStyle -- | Data structure for different methods of specifying precision. data PrecisionType -- | Specifies precision as a fixed number of significant digits SigFigs :: PrecisionType -- | Specifies precision with a fixed number of digits after the decimal -- place. Decimals :: PrecisionType -- | Different styles for representing negative numbers. data NegativeStyle -- | Shows negative numbers as -123.000 NegMinusSign :: NegativeStyle -- | Shows negative numbers as (123.000) NegParens :: NegativeStyle -- | Int format with no thousands separator. rawIntFmt :: NumFormat -- | Int format with comma as the thousands separator. intFmt :: NumFormat -- | Common format for percentages. Example: 75.000% percentFmt :: NumFormat -- | Common format for generic numeric quantities of the form 123,456.99. numFmt :: NumFormat -- | Common format for US dollar quantities of the form $123,456.99. usdFmt :: NumFormat nfUnits :: Lens NumFormat NumFormat Double Double nfPrefix :: Lens NumFormat NumFormat Text Text nfSuffix :: Lens NumFormat NumFormat Text Text nfThouSep :: Lens NumFormat NumFormat Text Text nfDecSep :: Lens NumFormat NumFormat Text Text nfStyle :: Lens NumFormat NumFormat NumStyle NumStyle nfPrec :: Lens NumFormat NumFormat (Maybe (Int, PrecisionType)) (Maybe (Int, PrecisionType)) nfNegStyle :: Lens NumFormat NumFormat NegativeStyle NegativeStyle -- | Generic floating point formatting function that allows you to specify -- your own underlying functions for formatting exponential and fixed -- formats. This can allow you to use more efficient versions if -- available. We also use it the test suite to check behavior against the -- old double-conversion implementation. formatNumGeneric :: Real a => (Maybe Int -> Double -> Text) -> (Maybe Int -> Double -> Text) -> NumFormat -> a -> Text instance Typeable NumFormat instance Eq NumStyle instance Show NumStyle instance Eq PrecisionType instance Show PrecisionType instance Eq NegativeStyle instance Show NegativeStyle instance Eq NumFormat instance Show NumFormat instance Eq a => Eq (RawNum a) instance Show a => Show (RawNum a) instance Default NumFormat -- | Practical formatting interface for output values intended for human -- consumption. We try to support several variants often required by -- real-world applications. module Formattable -- | Provides a uniform interface for formatting all kinds of types. class Format a where type family TheFormat a runFormat :: Format a => TheFormat a -> a -> Text -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = NumFormat -- | TheFormat = String -- | TheFormat = String -- | TheFormat = () -- | TheFormat = () instance Format Bool instance Format Text instance Format UTCTime instance Format Day instance Format Float instance Format Double instance Format Word64 instance Format Word32 instance Format Word16 instance Format Word8 instance Format Word instance Format Int64 instance Format Int32 instance Format Int16 instance Format Int8 instance Format Int instance Format Integer