ordinal-0.3.0.0: Convert numbers to words in different languages.

Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Text.Numerals.Class

Contents

Description

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

Typeclasses

class NumToWord a where Source #

A type class used for num to word algorithms. It maps an Integral type i to Text.

Minimal complete definition

toCardinal, toOrdinal, toShortOrdinal | toWords

Methods

toCardinal Source #

Arguments

:: 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.

toOrdinal Source #

Arguments

:: 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.

toShortOrdinal Source #

Arguments

:: 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.

toWords Source #

Arguments

:: 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.

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.

Methods

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.

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.

Constructors

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
Bounded NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Enum NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Eq NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Ord NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Read NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Show NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Default NumberType Source # 
Instance details

Defined in Text.Numerals.Class

Methods

def :: NumberType #

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.

Constructors

NumberSegment 

Fields

Instances
Functor NumberSegment Source # 
Instance details

Defined in Text.Numerals.Class

Methods

fmap :: (a -> b) -> NumberSegment a -> NumberSegment b #

(<$) :: a -> NumberSegment b -> NumberSegment a #

Foldable NumberSegment Source # 
Instance details

Defined in Text.Numerals.Class

Methods

fold :: Monoid m => NumberSegment m -> m #

foldMap :: Monoid m => (a -> m) -> NumberSegment a -> m #

foldr :: (a -> b -> b) -> b -> NumberSegment a -> b #

foldr' :: (a -> b -> b) -> b -> NumberSegment a -> b #

foldl :: (b -> a -> b) -> b -> NumberSegment a -> b #

foldl' :: (b -> a -> b) -> b -> NumberSegment a -> b #

foldr1 :: (a -> a -> a) -> NumberSegment a -> a #

foldl1 :: (a -> a -> a) -> NumberSegment a -> a #

toList :: NumberSegment a -> [a] #

null :: NumberSegment a -> Bool #

length :: NumberSegment a -> Int #

elem :: Eq a => a -> NumberSegment a -> Bool #

maximum :: Ord a => NumberSegment a -> a #

minimum :: Ord a => NumberSegment a -> a #

sum :: Num a => NumberSegment a -> a #

product :: Num a => NumberSegment a -> a #

Eq i => Eq (NumberSegment i) Source # 
Instance details

Defined in Text.Numerals.Class

Ord i => Ord (NumberSegment i) Source # 
Instance details

Defined in Text.Numerals.Class

Read i => Read (NumberSegment i) Source # 
Instance details

Defined in Text.Numerals.Class

Show i => Show (NumberSegment i) Source # 
Instance details

Defined in Text.Numerals.Class

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.