-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Convert numbers to number words -- -- This package contains machinery to construct functions that convert -- numbers to number words. It allows you to write a function which -- converts a number like 142 to the string "one hundred and forty-two". -- -- The documentation for the Text.Numeral module contains an high -- level overview of the package. -- -- If you just want to convert numbers to number words in a specific -- language you should probably use the numerals package. That -- package also contains numerous examples on how to use the functions in -- this package. @package numerals-base @version 0.3 module Text.Numeral.Misc -- | Raise 10 to some power. -- -- The (base 10) logarithm of an integral value. dec :: Integral α => α -> α intLog :: Integral α => α -> α module Text.Numeral.Exp.Classes -- | An unknown value. This is used to signal that a value can not be -- represented in the expression language. -- -- Law: isUnknown unknown == True class Unknown α unknown :: Unknown α => α isUnknown :: Unknown α => α -> Bool -- | A literal value. -- -- Example in English: -- --
-- "three" = lit 3 --class Lit α lit :: Lit α => ℤ -> α -- | Negation of a value. -- -- Example in English: -- --
-- "minus two" = neg (lit 2) --class Neg α neg :: Neg α => α -> α -- | Addition of two values. -- -- Example in English: -- --
-- "fifteen" = lit 5 `add` lit 10 --class Add α add :: Add α => α -> α -> α -- | Multiplication of two values. -- -- Example in English: -- --
-- "thirty" = lit 3 `mul` lit 10 --class Mul α mul :: Mul α => α -> α -> α -- | One value subtracted from another value. -- -- Example in Latin: -- --
-- "duodvgint" = lit 2 `sub` (lit 2 `mul` lit 10) --class Sub α sub :: Sub α => α -> α -> α -- | A step in a scale of large values. -- -- Should be interpreted as 10 ^ (rank * base + offset). -- -- Example in English: -- --
-- "quadrillion" = scale 3 3 4 --class Scale α scale :: Scale α => ℤ -> ℤ -> α -> α instance Scale ℤ instance Sub ℤ instance Mul ℤ instance Add ℤ instance Neg ℤ instance Lit ℤ instance Unknown ℤ module Text.Numeral.Exp -- | An expression that represents the structure of a numeral. data Exp -- | An unknown value. Unknown :: Exp -- | A literal value. Lit :: ℤ -> Exp -- | Negation of an expression. Neg :: Exp -> Exp -- | Addition of two expressions. Add :: Exp -> Exp -> Exp -- | Multiplication of two expressions. Mul :: Exp -> Exp -> Exp -- | One expression subtracted from another expression. Sub :: Exp -> Exp -> Exp -- | A step in a scale of large values. Scale :: ℤ -> ℤ -> Exp -> Exp -- | Evaluates an expression to a value. -- -- Law: e == eval e eval :: (Unknown α, Lit α, Neg α, Add α, Mul α, Sub α, Scale α) => Exp -> α -- | A side or direction, either Left or Right. data Side -- | Left. L :: Side -- | Right. R :: Side instance Eq Exp instance Ord Exp instance Show Exp instance Show Side instance Scale Exp instance Sub Exp instance Mul Exp instance Add Exp instance Neg Exp instance Lit Exp instance Unknown Exp module Text.Numeral.Render -- | Renders an expression to a string-like value according to a certain -- representation. render :: Monoid s => Repr s -> Exp -> Maybe s -- | A representation for numerals. -- -- A Repr contains all the information on how to render an -- Expression to a string-like value. data Repr s Repr :: Maybe s -> (ℤ -> Maybe (Ctx Exp -> s)) -> (ℤ -> ℤ -> Exp -> Ctx Exp -> Maybe s) -> Maybe (Exp -> Ctx Exp -> s) -> Maybe (Exp -> Exp -> Ctx Exp -> s) -> Maybe (Exp -> Exp -> Ctx Exp -> s) -> Maybe (Exp -> Exp -> Ctx Exp -> s) -> Maybe (s -> s -> s) -> Maybe (s -> s -> s -> s) -> Maybe (s -> s -> s -> s) -> Maybe (s -> s -> s -> s) -> Repr s -- | Representation for unknown values. reprUnknown :: Repr s -> Maybe s -- | Renders a literal value. Not necessarily defined for every value. reprValue :: Repr s -> ℤ -> Maybe (Ctx Exp -> s) -- | Renders a step in a scale of large values. The arguments are in order: -- base, offset and rank of the step and the context of the rank. The -- value represented by the step is 10 ^ (rank * base + offset). reprScale :: Repr s -> ℤ -> ℤ -> Exp -> Ctx Exp -> Maybe s -- | Renders a negation. This concerns the negation itself, not the thing -- being negated. reprNeg :: Repr s -> Maybe (Exp -> Ctx Exp -> s) -- | Renders an addition. This concerns the addition itself, not the things -- being added. For example: In "one hundred and eighty" this function -- would be responsible for rendering the "and". reprAdd :: Repr s -> Maybe (Exp -> Exp -> Ctx Exp -> s) -- | Renders a multiplication. This concerns the multiplication itself, not -- the things being multiplied. reprMul :: Repr s -> Maybe (Exp -> Exp -> Ctx Exp -> s) -- | Renders a subtraction. This concerns the subtraction itself, not the -- things being subtracted. reprSub :: Repr s -> Maybe (Exp -> Exp -> Ctx Exp -> s) -- | Combines a negation and the thing being negated. For example: this -- would combine "minus" and "three" into "minus three". reprNegCombine :: Repr s -> Maybe (s -> s -> s) -- | Combines an addition and the things being added. reprAddCombine :: Repr s -> Maybe (s -> s -> s -> s) -- | Combines a multiplication and the things being multiplied. reprMulCombine :: Repr s -> Maybe (s -> s -> s -> s) -- | Combines a subtraction and the things being subtracted. reprSubCombine :: Repr s -> Maybe (s -> s -> s -> s) -- | The default representation. -- -- Only the combining functions are defined. The rest are either -- Nothing or always produce Nothing. defaultRepr :: Monoid s => Repr s -- | A context in which an Expression appears. data Ctx α -- | The empty context. Used for top level expressions. CtxEmpty :: Ctx α -- | Negation context. CtxNeg :: (Ctx α) -> Ctx α -- | Addition context. CtxAdd :: Side -> α -> (Ctx α) -> Ctx α -- | Multiplication context. CtxMul :: Side -> α -> (Ctx α) -> Ctx α -- | Subtraction context. CtxSub :: Side -> α -> (Ctx α) -> Ctx α -- | Scale context. CtxScale :: (Ctx α) -> Ctx α instance Show α => Show (Ctx α) -- | Rules to convert numbers to an expression language. module Text.Numeral.Rules -- | A rule on how to convert a number into an expression language. Notice -- how this type is equal to the type of the $ operator. type Rule α β = (α -> β) -> (α -> β) -- | The 'if-then-else' concept for rules. Applies the first rule if the -- predicate holds on the input value, otherwise applies the second rule. conditional :: (α -> Bool) -> Rule α β -> Rule α β -> Rule α β -- | Tries to apply the first rule, if that produces an unknown -- value it applies the second rule. combine :: Unknown β => Rule α β -> Rule α β -> Rule α β -- | Chooses which rule to apply to an input value based on a interval list -- of rules. findRule :: (Ord α, Num α, Unknown β) => (α, Rule α β) -> [(α, Rule α β)] -> α -> Rule α β -- | A rule that always fails to convert a value. It constantly produces -- the unknown value. -- --
-- >>> (fix unknown) (3 :: Integer) :: Exp -- Unknown --unknown :: Unknown β => Rule α β -- |
-- >>> (pos $ lit $ fix unknown) (3 :: Integer) :: Exp -- Lit 3 -- -- >>> (pos $ lit $ fix unknown) (-3 :: Integer) :: Exp -- Neg (Lit 3) --pos :: (Ord α, Num α, Lit β, Neg β) => Rule α β -- |
-- >>> (checkPos $ lit $ fix unknown) (3 :: Integer) :: Exp -- Lit 3 -- -- >>> (checkPos $ lit $ fix unknown) (-3 :: Integer) :: Exp -- Unknown --checkPos :: (Ord α, Num α, Unknown β, Lit β) => Rule α β -- | The literal rule. Converts its argument into a literal -- expression. -- --
-- >>> lit (fix unknown) (3 :: Integer) :: Exp -- Lit 3 ---- -- In this example lit is applied to the nonsense rule "fix -- unknown". Lit ignores that function, which is why we can pass -- it anything we want, including itself. -- --
-- >>> lit (fix undefined) (3 :: Integer) :: Exp -- Lit 3 -- -- >>> (fix lit) (3 :: Integer) :: Exp -- Lit 3 --lit :: (Integral α, Lit β) => Rule α β -- | A variant on the lit rule which always multiplies its argument -- with 1. Useful for languages which have numerals of the form "one -- hundred and three" as opposed to "hundred and three". -- --
-- >>> lit1 (fix unknown) (3 :: Integer) :: Exp -- Mul (Lit 1) (Lit 3) --lit1 :: (Integral α, Lit β, Mul β) => Rule α β -- |
-- >>> (add 10 L $ lit $ fix unknown) (13 :: Integer) :: Exp -- Add (Lit 3) (Lit 10) --add :: (Num α, Add β) => α -> Side -> Rule α β -- |
-- >>> (mul 10 R L $ lit $ fix unknown) (42 :: Integer) :: Exp -- Add (Mul (Lit 4) (Lit 10)) (Lit 2) --mul :: (Integral α, Add β, Mul β) => α -> Side -> Side -> Rule α β mul1 :: (Integral α, Lit β, Add β, Mul β) => α -> Side -> Side -> Rule α β -- |
-- >>> (sub 20 $ lit $ fix unknown) (18 :: Integer) :: Exp -- Sub (Lit 2) (Lit 20) --sub :: (Integral α, Sub β) => α -> Rule α β mulScale :: (Integral α, Scale α, Add β, Mul β, Scale β) => α -> α -> Side -> Side -> Rule α β -> Rule α β mulScale1 :: (Integral α, Scale α, Add β, Mul β, Scale β) => α -> α -> Side -> Side -> Rule α β -> Rule α β shortScale :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β longScale :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β pelletierScale :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β shortScale1 :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β longScale1 :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β pelletierScale1 :: (Integral α, Scale α, Add β, Mul β, Scale β) => Side -> Side -> Rule α β -> Rule α β mkStep :: (Integral α, Unknown β, Lit β, Add β, Mul β) => Rule α β -> (α -> Side -> Rule α β) -> (α -> Side -> Side -> Rule α β) -> α -> α -> Side -> Side -> Rule α β step :: (Integral α, Unknown β, Lit β, Add β, Mul β) => α -> α -> Side -> Side -> Rule α β step1 :: (Integral α, Unknown β, Lit β, Add β, Mul β) => α -> α -> Side -> Side -> Rule α β module Text.Numeral module Text.Numeral.BigNum cardinal :: (Monoid s, IsString s, Integral α) => α -> Maybe s rule :: (Integral α, Unknown β, Lit β, Add β, Mul β) => Rule α β cardinalRepr :: (Monoid s, IsString s) => Repr s symMap :: (Integral α, IsString s) => Map α (Ctx Exp -> s) forms :: s -> s -> s -> s -> s -> Ctx Exp -> s scaleRepr :: (IsString s, Monoid s) => s -> s -> [(ℤ, Ctx Exp -> s)] -> ℤ -> ℤ -> Exp -> Ctx Exp -> Maybe s pelletierRepr :: (IsString s, Monoid s) => s -> s -> s -> s -> [(ℤ, Ctx Exp -> s)] -> ℤ -> ℤ -> Exp -> Ctx Exp -> Maybe s