-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Utilities for working with numerals -- -- Utilities for working with numerals @package numerals @version 0.1 -- | Parsing and pretty printing of Roman numerals. -- -- This module provides functions for parsing and pretty printing Roman -- numerals. Because the notation of Roman numerals has varied through -- the centuries this package allows for some customisation using a -- configuration that is passed to the conversion functions. Exceptions -- are dealt with by wrapping the results of conversions in the error -- monad. module Text.Numeral.Roman -- | A configuration with which the convertTo and convertFrom -- functions can be parameterized. data NumeralConfig s n NC :: n -> Maybe s -> [(s, n)] -> NumeralConfig s n -- | The largest value that can be represented using this configuration. ncMax :: NumeralConfig s n -> n -- | Symbol to represent the value 0. The Romans did not have a symbol for -- zero. If set to Nothing a convertFrom 0 will throw an error. ncZero :: NumeralConfig s n -> Maybe s -- | A table of symbols and their numerical values. The table must be -- ordered with the largest symbols appearing first. If any symbol is the -- empty string then convertFrom will be undefined. If any symbol -- in this table is associated with the value 0 both the convertTo and -- convertFrom function will be undefined. ncTable :: NumeralConfig s n -> [(s, n)] -- | Configuration for Roman numerals as they are commonly used today. The -- value 0 is represented by the empty string. It can be interpreted as -- not writing down a number. This configuration is limited to the range -- [1..3999]. Larger numbers can be represented using Roman numerals but -- you will need notations that are hard or impossible to express using -- strings. modernRoman :: (IsString s, Ord n, Num n) => NumeralConfig s n -- | Configuration for Roman numerals that do not use the rule that a lower -- rank symbol can be placed before a higher rank symbol to denote the -- difference between them. Thus a numeral like IV will not be -- accepted or generated by this configuration. simpleRoman :: (IsString s, Ord n, Num n) => NumeralConfig s n -- | Converts a number to a Roman numeral according to the given -- configuration. Numbers which are out of bounds will cause exceptions -- to be thrown. An exception will also be raised if no representation is -- possible with the given configuration. If the value of any symbol in -- the configuration is equal to 0 or a symbol is the empty string this -- function is undefined. convertTo :: (Monoid s, Ord n, Num n, MonadError String m) => NumeralConfig s n -> n -> m s -- | Like convertTo, but exceptions are promoted to errors. unsafeConvertTo :: (Monoid s, Ord n, Num n) => NumeralConfig s n -> n -> s -- | Converts a number to a modern Roman numeral. See convertTo for -- possible exceptions. toRoman :: (IsString s, Monoid s, Ord n, Num n, MonadError String m) => n -> m s -- | Like toRoman, but exceptions are promoted to errors. unsafeToRoman :: (IsString s, Monoid s, Ord n, Num n) => n -> s -- | Parses a string as a Roman numeral according to the given -- configuration. An exception will be raised if the input is not a valid -- numeral. convertFrom :: (Monoid s, StripPrefix s, Eq s, Ord n, Num n, MonadError String m) => NumeralConfig s n -> s -> m n -- | Parses a string as a modern Roman numeral. See convertFrom for -- possible exceptions. fromRoman :: (IsString s, Monoid s, StripPrefix s, Eq s, Ord n, Num n, MonadError String m) => s -> m n -- | Like convertFrom, but exceptions are promoted to errors. unsafeConvertFrom :: (Monoid s, StripPrefix s, Eq s, Ord n, Num n) => NumeralConfig s n -> s -> n -- | Like fromRoman, but exceptions are promoted to errors. unsafeFromRoman :: (IsString s, Monoid s, StripPrefix s, Eq s, Ord n, Num n) => s -> n instance StripPrefix ByteString instance Eq a => StripPrefix [a] module Text.Numeral.Positional toPositional :: (IsString s, Monoid s) => (Integer -> s) -> Integer -> Integer -> Maybe s digitSymbol :: IsString s => Integer -> s binary :: (Monoid s, IsString s) => Integer -> Maybe s negabinary :: (Monoid s, IsString s) => Integer -> Maybe s ternary :: (Monoid s, IsString s) => Integer -> Maybe s octal :: (Monoid s, IsString s) => Integer -> Maybe s decimal :: (Monoid s, IsString s) => Integer -> Maybe s negadecimal :: (Monoid s, IsString s) => Integer -> Maybe s hexadecimal :: (Monoid s, IsString s) => Integer -> Maybe s module Text.Numeral.Misc withSnd :: (a -> b -> c) -> (d, a) -> (e, b) -> c d :: Integer -> Integer const2 :: a -> b -> c -> a weave :: [a] -> [a] -> [a] untilNothing :: [Maybe a] -> [a] module Text.Numeral.Joinable -- | Class of string-like types which can be joined. class Joinable s (<>) :: Joinable s => s -> s -> s (<+>) :: Joinable s => s -> s -> s (<->) :: (Joinable s, IsString s) => s -> s -> s space :: (Joinable s, IsString s) => s -> s -> s instance IsString Doc instance IsString ShowS instance Joinable Doc instance Joinable DString instance Joinable ShowS instance Joinable Text instance Joinable ByteString instance Joinable String module Text.Numeral data NumConfig s NumConfig :: (Integer -> Maybe (NumSymbol s)) -> (s -> s) -> ((Integer, s) -> s) -> ((Integer, s) -> (Integer, s) -> s) -> ((Integer, s) -> (Integer, s) -> s) -> NumConfig s ncCardinal :: NumConfig s -> Integer -> Maybe (NumSymbol s) ncNeg :: NumConfig s -> s -> s ncOne :: NumConfig s -> (Integer, s) -> s ncAdd :: NumConfig s -> (Integer, s) -> (Integer, s) -> s ncMul :: NumConfig s -> (Integer, s) -> (Integer, s) -> s data NumSymbol s NumSym :: SymbolType -> Integer -> Integer -> (Gender -> SymbolContext -> s) -> NumSymbol s symType :: NumSymbol s -> SymbolType symVal :: NumSymbol s -> Integer symScope :: NumSymbol s -> Integer symRepr :: NumSymbol s -> Gender -> SymbolContext -> s data SymbolType Terminal :: SymbolType Add :: SymbolType Mul :: SymbolType data SymbolContext EmptyContext :: SymbolContext LA :: Integer -> SymbolContext -> SymbolContext RA :: Integer -> SymbolContext -> SymbolContext LM :: Integer -> SymbolContext -> SymbolContext RM :: Integer -> SymbolContext -> SymbolContext -- | Grammatical gender data Gender Neuter :: Gender Masculine :: Gender Feminine :: Gender cardinal :: NumConfig s -> Gender -> Integer -> Maybe s findSym :: [NumSymbol s] -> Integer -> Maybe (NumSymbol s) term :: Integer -> (SymbolContext -> s) -> NumSymbol s add :: Integer -> Integer -> (SymbolContext -> s) -> NumSymbol s mul :: Integer -> (SymbolContext -> s) -> NumSymbol s termG :: Integer -> (Gender -> SymbolContext -> s) -> NumSymbol s addG :: Integer -> Integer -> (Gender -> SymbolContext -> s) -> NumSymbol s mulG :: Integer -> (Gender -> SymbolContext -> s) -> NumSymbol s gender :: s -> s -> (Gender -> s) genderN :: s -> s -> s -> (Gender -> s) -- | Constructs a symbol representation based on the relation of the symbol -- with the number 10. The chosen representation depends on the context -- in which the symbol is used: d) default: x a) additive: 10 + x m) -- multiplicative: x * 10 tenForms :: s -> s -> s -> (SymbolContext -> s) tenFormsG :: (Gender -> s) -> (Gender -> s) -> (Gender -> s) -> (Gender -> SymbolContext -> s) -- | Constructs a symbol representation based on the relation of the symbol -- with the number 10. The chosen representation depends on the context -- in which the symbol is used: d) default: x a) additive: 10 + x mt) -- multiplicative: x * 10 mh) multiplicative: x * 100 tenForms' :: s -> s -> s -> s -> (SymbolContext -> s) mulForms :: s -> s -> (SymbolContext -> s) instance Show Gender instance Show SymbolContext instance Show SymbolType module Text.Numeral.Language.DE de :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.SV sv :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.NO no :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.LA la :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.SP sp :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.JA ja :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.EO eo :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Pelletier longScale :: (IsString s, Joinable s) => s -> s -> [NumSymbol s] longScalePlural :: (IsString s, Joinable s) => s -> s -> s -> s -> [NumSymbol s] shortScale :: (IsString s, Joinable s) => s -> [NumSymbol s] shortScalePlural :: (IsString s, Joinable s) => s -> s -> [NumSymbol s] module Text.Numeral.Language.NL nl :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.EN enShort :: (IsString s, Joinable s) => NumConfig s enLong :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.FR fr :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.IT it :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language.PT pt :: (IsString s, Joinable s) => NumConfig s module Text.Numeral.Language