numerals-0.4.1: Convert numbers to number words

Safe HaskellSafe
LanguageHaskell98

Text.Numeral.Render

Contents

Synopsis

Rendering numerals

render Source #

Arguments

:: Repr

Representation.

-> Inflection

Initial inflection.

-> Exp

The expression to render.

-> Maybe Text 

Renders an expression to a Text value according to a certain representation and inflection.

Representation of numerals

data Repr Source #

A representation for numerals.

A Repr contains all the information on how to render an Expression to a Text value.

Constructors

Repr 

Fields

type ScaleRepr Source #

Arguments

 = Inflection 
-> Integer

Base.

-> Integer

Offset.

-> Exp

Rank.

-> Ctx Exp

Rank context.

-> Maybe Text 

Function that renders the representation of a step in a scale of large values. The value represented by the step is 10 ^ (rank * base + offset).

defaultRepr :: Repr Source #

The default representation.

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

Context of expressions

data Ctx a Source #

A context in which an Expression appears.

Constructors

CtxEmpty

The empty context. Used for top level expressions.

CtxNeg (Ctx a)

Negation context.

CtxAdd Side a (Ctx a)

Addition context.

CtxMul Side a (Ctx a)

Multiplication context.

CtxSub Side a (Ctx a)

Subtraction context.

CtxFrac Side a (Ctx a)

Fraction context.

CtxScale (Ctx a)

Scale context.

Instances

Eq a => Eq (Ctx a) Source # 

Methods

(==) :: Ctx a -> Ctx a -> Bool #

(/=) :: Ctx a -> Ctx a -> Bool #

Show a => Show (Ctx a) Source # 

Methods

showsPrec :: Int -> Ctx a -> ShowS #

show :: Ctx a -> String #

showList :: [Ctx a] -> ShowS #

isOutside :: Side -> Ctx a -> Bool Source #

Checks whether a context is completely on the outside of an expression, either left or right.

Given the following expression:

Add (Lit 1000) (Add (Mul (Lit 2) (Lit 100)) (Add (Lit 4) (Mul (Lit 3) (Lit 10))))

On the left we have Lit 1000 and on the right Lit 10.