numerals-base-0.3: Convert numbers to number words

Text.Numeral.Render

Contents

Synopsis

Rendering numerals

render :: Monoid s => Repr s -> Exp -> Maybe sSource

Renders an expression to a string-like value according to a certain representation.

Representation of numerals

data Repr s Source

A representation for numerals.

A Repr contains all the information on how to render an Expression to a string-like value.

Constructors

Repr 

Fields

reprUnknown :: Maybe s

Representation for unknown values.

reprValue :: -> Maybe (Ctx Exp -> s)

Renders a literal value. Not necessarily defined for every value.

reprScale :: -> -> Exp -> Ctx Exp -> Maybe 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).

reprNeg :: Maybe (Exp -> Ctx Exp -> s)

Renders a negation. This concerns the negation itself, not the thing being negated.

reprAdd :: Maybe (Exp -> 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".

reprMul :: Maybe (Exp -> Exp -> Ctx Exp -> s)

Renders a multiplication. This concerns the multiplication itself, not the things being multiplied.

reprSub :: Maybe (Exp -> Exp -> Ctx Exp -> s)

Renders a subtraction. This concerns the subtraction itself, not the things being subtracted.

reprNegCombine :: Maybe (s -> s -> s)

Combines a negation and the thing being negated. For example: this would combine "minus" and "three" into "minus three".

reprAddCombine :: Maybe (s -> s -> s -> s)

Combines an addition and the things being added.

reprMulCombine :: Maybe (s -> s -> s -> s)

Combines a multiplication and the things being multiplied.

reprSubCombine :: Maybe (s -> s -> s -> s)

Combines a subtraction and the things being subtracted.

defaultRepr :: Monoid s => Repr sSource

The default representation.

Only the combining functions are defined. The rest are either Nothing or always produce Nothing.

Context of expressions

data Ctx α Source

A context in which an Expression appears.

Constructors

CtxEmpty

The empty context. Used for top level expressions.

CtxNeg (Ctx α)

Negation context.

CtxAdd Side α (Ctx α)

Addition context.

CtxMul Side α (Ctx α)

Multiplication context.

CtxSub Side α (Ctx α)

Subtraction context.

CtxScale (Ctx α)

Scale context.

Instances

Show α => Show (Ctx α)