Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
A module that defines the typeclasses that are used in the rest of the module. The NumToWord
class
is the typeclass that is used by all algorithmic conversion tools.
Synopsis
- class NumToWord a where
- toCardinal :: Integral i => a -> i -> Text
- toOrdinal :: Integral i => a -> i -> Text
- toShortOrdinal :: Integral i => a -> i -> Text
- toWords :: Integral i => NumberType -> a -> i -> Text
- class ValueSplit a where
- valueSplit :: a -> FreeValueSplitter
- data NumberType
- data NumberSegment i = NumberSegment {}
- type MNumberSegment i = Maybe (NumberSegment i)
- type NumberToWords i = i -> Text
- type FreeNumberToWords = forall i. Integral i => NumberToWords i
- type MergerFunction i = i -> i -> Text -> Text -> Text
- type FreeMergerFunction = forall i. Integral i => MergerFunction i
- type ValueSplitter i = i -> Maybe (i, Text)
- type FreeValueSplitter = forall i. Integral i => ValueSplitter i
- type NumberSegmenting i = i -> NumberSegment i
Typeclasses
class NumToWord a where Source #
:: Integral i | |
=> a | The conversion algorithm that transforms the number into words. |
-> i | The number to transform into a cardinal form. |
-> Text | The number in words in a cardinal form. |
Convert the given number to a Text
object that is the given number in
words in cardinal form.
:: Integral i | |
=> a | The conversion algorithm that transforms the number into words. |
-> i | The number to transform into a ordinal form. |
-> Text | The number in words in a ordinal form. |
Convert the given number to a Text
object that is the given number in
words in cardinal form.
:: Integral i | |
=> a | The conversion algorithm that transforms the number into words. |
-> i | The number to transform into a ordinal form. |
-> Text | The number in words in a ordinal form. |
Convert the given number to a Text
object that is the given number
in words in short cardinal form.
:: Integral i | |
=> NumberType | The given format to convert the number to. |
-> a | The conversion algorithm that transforms the number into words. |
-> i | The number to transform into the given form. |
-> Text | The number in words in the given form. |
Convert the given number to a Text
object that is the given number in
words in the given NumberType
.
Instances
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 # |
class ValueSplit a where Source #
A type class used to split a value, based on the name of a number in a specific language. The value that is used to split, is often, depending on the language, the largest value smaller than the given number.
valueSplit :: a -> FreeValueSplitter Source #
A function that takes an Integral
value, and based on the object
splits it with a value and the name of the number in a specific language.
Instances
ValueSplit HighNumberAlgorithm Source # | |
Defined in Text.Numerals.Algorithm |
Types of numbers
data NumberType Source #
A data type that specifies the different types of numbers. These can be
used to specify the "target format". The Default
number type is Cardinal
.
Cardinal | Cardinal numbers like one, two, three, etc. |
Ordinal | Ordinal numbers like first, second, third, etc. |
ShortOrdinal | Short ordinal numbers like 1st, 2nd, 3rd, etc. |
Instances
Segmenting a number
data NumberSegment i Source #
A data type used to convert a number into segments. Each segment has an optional division and remainder part, together with a value and the name of that value in a language.
NumberSegment | |
|
Instances
type MNumberSegment i = Maybe (NumberSegment i) Source #
A Maybe
variant of the NumberSegment
data type. This is used since the
division part can be one, or the remainder part can be zero.
Utility type synonyms
type NumberToWords i = i -> Text Source #
A type alias for a function that maps a number to a Text
object.
type FreeNumberToWords = forall i. Integral i => NumberToWords i Source #
A type alias for a NumberToWords
function, with a free Integral
variable.
type MergerFunction i = i -> i -> Text -> Text -> Text Source #
A type alias of a function that is used to merge the names of two numbers according to gramatical rules. The type parameter is the type of the numbers to merge.
type FreeMergerFunction = forall i. Integral i => MergerFunction i Source #
A type alias of a MergerFunction
function with a free Integral
variable.
type ValueSplitter i = i -> Maybe (i, Text) Source #
A type alias of a function that maps a number to a 2-tuple that contains a
number and the word for that number. This number is normally the largest
number smaller than the given number. In case no name exists for a number
smaller than the given one Nothing
is returned.
type FreeValueSplitter = forall i. Integral i => ValueSplitter i Source #
A type alias of a ValueSplitter
function, with a free Integral
variable.
type NumberSegmenting i = i -> NumberSegment i Source #
A type alias of a function that converts a number to a NumberSegment
for that number.