Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
A module that contains data types and functions to automatically convert a number to words. It has tooling for a NumeralsAlgorithm
as well as a HighNumberAlgorithm
that is used to generate a ShortScale
or LongScale
.
Synopsis
- data NumeralsAlgorithm
- numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> ClockText -> NumeralsAlgorithm
- data HighNumberAlgorithm
- shortScale :: Text -> FreeValueSplitter
- longScale :: Text -> Text -> FreeValueSplitter
- shortScaleTitle :: Text -> FreeValueSplitter
- longScaleTitle :: Text -> Text -> FreeValueSplitter
- valueSplit' :: (Text -> Text) -> HighNumberAlgorithm -> FreeValueSplitter
- toSegments :: Integral i => Vector Text -> [(Integer, Text)] -> ValueSplitter i -> NumberSegmenting i
- toSegmentLow :: Integral i => Vector Text -> NumberSegmenting i
- toSegmentMid :: Integral i => Vector Text -> [(Integer, Text)] -> NumberSegmenting i
- toSegmentHigh :: Integral i => Vector Text -> [(Integer, Text)] -> ValueSplitter i -> NumberSegmenting i
- compressSegments :: Integral i => Text -> MergerFunction i -> NumberSegment i -> Text
Data types for number algorithms
data NumeralsAlgorithm Source #
A data type for algorithmic number to word conversions. Most western languages likely can work with this data type.
Instances
Default NumeralsAlgorithm Source # | |
Defined in Text.Numerals.Languages.English | |
NumToWord NumeralsAlgorithm Source # | |
Defined in Text.Numerals.Algorithm toCardinal :: Integral i => NumeralsAlgorithm -> i -> Text Source # toOrdinal :: Integral i => NumeralsAlgorithm -> i -> Text Source # toShortOrdinal :: Integral i => NumeralsAlgorithm -> i -> Text Source # toWords :: Integral i => NumberType -> NumeralsAlgorithm -> i -> Text Source # toTimeText :: NumeralsAlgorithm -> TimeOfDay -> Text Source # toTimeText' :: NumeralsAlgorithm -> Int -> Int -> Text Source # |
numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> ClockText -> NumeralsAlgorithm Source #
A smart constructor for the NumeralsAlgorithm
type. This constructor
allows one to use an arbitrary Foldable
type for the low words and mid
words. It will also order the midwords accordingly.
Large number algorithms
data HighNumberAlgorithm Source #
A data type used for to map larger numbers to words. This data type
supports the short scale and long scale with Latin prefixes, and
custom suffixes. The Default
value is the short scale with illion
as suffix. This is used in English for large numbers.
Instances
shortScale :: Text -> FreeValueSplitter Source #
Construct a FreeValueSplitter
function for the given suffix for a short scale.
longScale :: Text -> Text -> FreeValueSplitter Source #
Construct a FreeValueSplitter
function for the given suffixes for a long scale.
shortScaleTitle :: Text -> FreeValueSplitter Source #
Construct a FreeValueSplitter
function for the given suffix for a short scale, the names are written in title case.
longScaleTitle :: Text -> Text -> FreeValueSplitter Source #
Construct a FreeValueSplitter
function for the given suffixes for a long scale, the names are written in title case.
:: (Text -> Text) | The post-processing function. |
-> HighNumberAlgorithm | The |
-> FreeValueSplitter | The |
Generate a value splitter for a HighNumberAlgorithm
but where the result
is post-processed by a function.
Conversion to a NumberSegment
:: Integral i | |
=> Vector Text | A |
-> [(Integer, Text)] | The list of name and the names of these numbers in descending order for the mid words. |
-> ValueSplitter i | The |
-> NumberSegmenting i | The function that maps the number to the |
Convert the given number to a NumberSegment
with the given Vector
of
low numbers, the sorted list of mid numbers, and a FreeValueSplitter
for
large numbers.
:: Integral i | |
=> Vector Text | A |
-> NumberSegmenting i | The function that maps the number to the |
Convert the given number to a NumberSegment
with the given Vector
of
low numbers. Mid words and large numbers are not taken into account. This
is often the next step after the toSegmentMid
.
:: Integral i | |
=> Vector Text | A |
-> [(Integer, Text)] | The list of name and the names of these numbers in descending order for the mid words. |
-> NumberSegmenting i | The function that maps the number to the |
Convert the given number to a NumberSegment
with the given Vector
of
low numbers, and the sorted list of mid numbers. Large numbers are not
taken into account. This is often the next step after the toSegmentHigh
.
:: Integral i | |
=> Vector Text | A |
-> [(Integer, Text)] | The list of name and the names of these numbers in descending order for the mid words. |
-> ValueSplitter i | The |
-> NumberSegmenting i | The function that maps the number to the |
Convert the given number to a NumberSegment
with the given Vector
of
low numbers, the sorted list of mid numbers, and a FreeValueSplitter
for
large numbers.
Segment compression
:: Integral i | |
=> Text | The value used for one in the specific language. |
-> MergerFunction i | The |
-> NumberSegment i | The given |
-> Text | The |
Use the given MergerFunction
to compress the NumberSegment
to a single
Text
object that represents the given number.