ordinal-0.4.0.6: Convert numbers to words in different languages.
Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Text.Numerals.Class

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), (toTimeText | toTimeText')

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.

toTimeText Source #

Arguments

:: a

The conversion algorithm to transform numbers into words.

-> TimeOfDay

The time of the day to convert to words.

-> Text

The time as text.

Convert the given time of the day to text describing that time.

toTimeText' Source #

Arguments

:: a

The conversion algorithm to transform numbers into words.

-> Int

The number of hours, between 0 and 23 (both inclusive)

-> Int

The number of minutes, beween 0 and 59 (both inclusive)

-> Text

The time as text.

Convert the given hours and minutes to text that describes the time.

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.

Instances

Instances details
ValueSplit HighNumberAlgorithm Source # 
Instance details

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.

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

Instances details
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

Arbitrary 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

Instances details
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 #

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 #

Arbitrary1 NumberSegment Source # 
Instance details

Defined in Text.Numerals.Class

Methods

liftArbitrary :: Gen a -> Gen (NumberSegment a) #

liftShrink :: (a -> [a]) -> NumberSegment a -> [NumberSegment 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

Arbitrary i => Arbitrary (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.

Segments of time

data ClockSegment Source #

A data type that describes the state of the minutes within an hour.

Constructors

OClock

The number of minutes is zero.

Past Int

The parameter is the number of minutes past the hour, this is between 1 and 14.

QuarterPast

It is a quarter past the hour.

ToHalf Int

The parameter is the number of minutes until half, this is between 1 and 14.

Half

It is half past an hour.

PastHalf Int

The parameter is the number of minutes past half, this is between 1 and 14.

QuarterTo

It is a quarter to an hour.

To Int

The parameter is the number of minutes to the next hour, this is between 1 and 14.

data DayPart Source #

A data type that describes the state of the hours within a day.

Constructors

Night

It is night, this means that it is between 0:00 and 5:59.

Morning

It is morning, this means that it is between 6:00 and 11:59.

Afternoon

It is afternoon, this means it is between 12:00 and 17:59.

Evening

It is evening, this means it is between 18:00 and 23:59.

Instances

Instances details
Bounded DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Enum DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Eq DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Methods

(==) :: DayPart -> DayPart -> Bool #

(/=) :: DayPart -> DayPart -> Bool #

Ord DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Read DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Show DayPart Source # 
Instance details

Defined in Text.Numerals.Class

Arbitrary DayPart Source # 
Instance details

Defined in Text.Numerals.Class

data DaySegment Source #

A data type that describes the part of the day, and the number of hours on a 12-hour clock.

Constructors

DaySegment 

Fields

toDayPart Source #

Arguments

:: Int

The given number of hours.

-> DayPart

The corresponding DayPart.

Convert the given number of hours to the corresponding DayPart.

toDaySegment Source #

Arguments

:: Int

The given number of hours.

-> DaySegment

The corresponding DaySegment.

Convert the given number of hours to the corresponding DaySegment.

toClockSegment Source #

Arguments

:: Int

The number of minutes.

-> ClockSegment

The corresponding ClockSegment.

Convert the given number of minutes to the corresponding ClockSegment.

hourCorrection Source #

Arguments

:: Int

The value for the number of hours.

-> Int

The hours in the 1 .. 12 range.

Correct the hour to a 12 number segment. The input can be any Int number, whereas the result will be in the 1 .. 12 range.

Convert the current time to words

currentTimeText Source #

Arguments

:: NumToWord a 
=> TimeZone

The given TimeZone.

-> a

The NumToWord algorithm that converts time to words.

-> IO Text

An IO that will generate a Text object that describes the current time in words.

Convert the current time in the given TimeZone to the time in words with the given NumToWord algorithm.

currentTimeText' Source #

Arguments

:: NumToWord a 
=> a

The NumToWord algorithm that converts time to words.

-> IO Text

An IO that will generate a Text object that describes the current time in words.

Convert the current time to the time in words with the given NumToWord algorithm as UTC time.

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.

type ClockText Source #

Arguments

 = ClockSegment

The ClockSegment that describes the state of minutes within an hour.

-> DaySegment

The DaySegment that describes the state of hours within a day.

-> Int

The number of hours.

-> Int

The number of minutes.

-> Text

A Text object that describes the given time.

The type of a function that converts time to its description. The first two parameters are used to make conversion more convenient.