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
- toTimeText :: a -> TimeOfDay -> Text
- toTimeText' :: a -> Int -> Int -> Text
- class ValueSplit a where
- valueSplit :: a -> FreeValueSplitter
- data NumberType
- data NumberSegment i = NumberSegment {}
- type MNumberSegment i = Maybe (NumberSegment i)
- data ClockSegment
- data DayPart
- data DaySegment = DaySegment {}
- toDayPart :: Int -> DayPart
- toDaySegment :: Int -> DaySegment
- toClockSegment :: Int -> ClockSegment
- hourCorrection :: Int -> Int
- currentTimeText :: NumToWord a => TimeZone -> a -> IO Text
- currentTimeText' :: NumToWord a => a -> IO Text
- 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
- type ClockText = ClockSegment -> DaySegment -> Int -> Int -> Text
Typeclasses
class NumToWord a where Source #
(toCardinal, toOrdinal, toShortOrdinal | toWords), (toTimeText | toTimeText')
:: 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
.
:: 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.
:: 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.
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 # toTimeText :: NumeralsAlgorithm -> TimeOfDay -> Text Source # toTimeText' :: NumeralsAlgorithm -> Int -> Int -> 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
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.
Segments of time
data ClockSegment Source #
A data type that describes the state of the minutes within an hour.
OClock | The number of minutes is zero. |
Past Int | The parameter is the number of minutes past the hour, this is between |
QuarterPast | It is a quarter past the hour. |
ToHalf Int | The parameter is the number of minutes until half, this is between |
Half | It is half past an hour. |
PastHalf Int | The parameter is the number of minutes past half, this is between |
QuarterTo | It is a quarter to an hour. |
To Int | The parameter is the number of minutes to the next hour, this is between |
Instances
Eq ClockSegment Source # | |
Defined in Text.Numerals.Class (==) :: ClockSegment -> ClockSegment -> Bool # (/=) :: ClockSegment -> ClockSegment -> Bool # | |
Ord ClockSegment Source # | |
Defined in Text.Numerals.Class compare :: ClockSegment -> ClockSegment -> Ordering # (<) :: ClockSegment -> ClockSegment -> Bool # (<=) :: ClockSegment -> ClockSegment -> Bool # (>) :: ClockSegment -> ClockSegment -> Bool # (>=) :: ClockSegment -> ClockSegment -> Bool # max :: ClockSegment -> ClockSegment -> ClockSegment # min :: ClockSegment -> ClockSegment -> ClockSegment # | |
Read ClockSegment Source # | |
Defined in Text.Numerals.Class readsPrec :: Int -> ReadS ClockSegment # readList :: ReadS [ClockSegment] # | |
Show ClockSegment Source # | |
Defined in Text.Numerals.Class showsPrec :: Int -> ClockSegment -> ShowS # show :: ClockSegment -> String # showList :: [ClockSegment] -> ShowS # | |
Arbitrary ClockSegment Source # | |
Defined in Text.Numerals.Class arbitrary :: Gen ClockSegment # shrink :: ClockSegment -> [ClockSegment] # |
A data type that describes the state of the hours within a day.
Night | It is night, this means that it is between |
Morning | It is morning, this means that it is between |
Afternoon | It is afternoon, this means it is between |
Evening | It is evening, this means it is between |
Instances
Bounded DayPart Source # | |
Enum DayPart Source # | |
Eq DayPart Source # | |
Ord DayPart Source # | |
Read DayPart Source # | |
Show DayPart Source # | |
Arbitrary DayPart Source # | |
data DaySegment Source #
A data type that describes the part of the day, and the number of hours on a 12-hour clock.
Instances
Eq DaySegment Source # | |
Defined in Text.Numerals.Class (==) :: DaySegment -> DaySegment -> Bool # (/=) :: DaySegment -> DaySegment -> Bool # | |
Ord DaySegment Source # | |
Defined in Text.Numerals.Class compare :: DaySegment -> DaySegment -> Ordering # (<) :: DaySegment -> DaySegment -> Bool # (<=) :: DaySegment -> DaySegment -> Bool # (>) :: DaySegment -> DaySegment -> Bool # (>=) :: DaySegment -> DaySegment -> Bool # max :: DaySegment -> DaySegment -> DaySegment # min :: DaySegment -> DaySegment -> DaySegment # | |
Read DaySegment Source # | |
Defined in Text.Numerals.Class readsPrec :: Int -> ReadS DaySegment # readList :: ReadS [DaySegment] # readPrec :: ReadPrec DaySegment # readListPrec :: ReadPrec [DaySegment] # | |
Show DaySegment Source # | |
Defined in Text.Numerals.Class showsPrec :: Int -> DaySegment -> ShowS # show :: DaySegment -> String # showList :: [DaySegment] -> ShowS # | |
Arbitrary DaySegment Source # | |
Defined in Text.Numerals.Class arbitrary :: Gen DaySegment # shrink :: DaySegment -> [DaySegment] # |
Convert the given number of hours to the corresponding DayPart
.
:: Int | The given number of hours. |
-> DaySegment | The corresponding |
Convert the given number of hours to the corresponding DaySegment
.
:: Int | The number of minutes. |
-> ClockSegment | The corresponding |
Convert the given number of minutes to the corresponding ClockSegment
.
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
:: NumToWord a | |
=> a | The |
-> IO Text | An |
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.
= ClockSegment | The |
-> DaySegment | The |
-> Int | The number of hours. |
-> Int | The number of minutes. |
-> Text | A |
The type of a function that converts time to its description. The first two parameters are used to make conversion more convenient.