pandoc-crossref-0.3.16.0: Pandoc filter for cross-references
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.Numeral.Roman

Description

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.

Example:

>>> toRoman 1729 :: String
"MDCCXXIX"
>>> fromRoman "MDCCXXIX" :: Maybe Integer
Just 1729
>>> fromRoman "Bla" :: Maybe Integer
Nothing
Synopsis

Types

data NumeralConfig n Source #

A configuration with which the convertTo and convertFrom functions can be parameterized.

mkNumConfig Source #

Arguments

:: (Ord n, Num n) 
=> Text

Symbol for zero

-> Text

Symbol for one

-> [(Text, n)]

Symbol-value table.

-> NumeralConfig n 

Smart constructor for a NumeralConfig.

Pretty printing

convertTo :: (Ord n, Num n) => NumeralConfig n -> n -> Text Source #

Converts a number to a Roman numeral according to the given configuration.

Parsing

convertFrom :: (Ord n, Num n) => NumeralConfig n -> Text -> Maybe n Source #

Parses a string as a Roman numeral according to the given configuration. Result is Nothing if the input is not a valid numeral.

Default Configurations

modernRoman :: (Ord n, Num n) => NumeralConfig n Source #

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 practically limited to the range [1..3999]. Smaller numbers will result in an empty string. Larger numbers will result in repeated use of the 'M' symbol.

Utility

toRoman :: (Ord n, Num n) => n -> Text Source #

Converts a number to a modern Roman numeral.

fromRoman :: (Ord n, Num n) => Text -> Maybe n Source #

Parses a string as a modern Roman numeral.