Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
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) -> NumeralsAlgorithm
- data HighNumberAlgorithm
- shortScale :: Text -> FreeValueSplitter
- longScale :: Text -> Text -> 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
NumToWord NumeralsAlgorithm Source # | |
Defined in Text.Numerals.Algorithm toCardinal :: Integral i => NumeralsAlgorithm -> i -> Text Source # toOrdinal :: Integral i => NumeralsAlgorithm -> i -> Text Source # toWords :: Integral i => NumberType -> NumeralsAlgorithm -> i -> Text Source # |
numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> 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.
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.
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.