Data.Digits

digits-0.3.1: Converts integers to lists of digits and back.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Digits

Synopsis

- mDigits :: Integral n => n -> n -> Maybe [n]
- digits :: Integral n => n -> n -> [n]
- mDigitsRev :: Integral n => n -> n -> Maybe [n]
- digitsRev :: Integral n => n -> n -> [n]
- unDigits :: Integral n => n -> [n] -> n
- prop_digitsRoundTrip :: Integer -> Integer -> Property

# Documentation

mDigits #

Arguments

:: Integral n |
=> n | The base to use.
-> n | The number to convert to digit form.
-> Maybe [n] | Nothing or Just the digits of the number in list form

Returns the digits of a positive integer as a Maybe list. or Nothing if a zero or negative base is given

digits #

Arguments

:: Integral n |
=> n | The base to use (typically 10).
-> n | The number to convert to digit form.
-> [n] | Either Nothing or the digits of the number in list form.

Returns the digits of a positive integer as a list. Throws an error if given a zero or negative base.

mDigitsRev #

Arguments

:: Integral n |
=> n | The base to use.
-> n | The number to convert to digit form.
-> Maybe [n] | Nothing or Just the digits of the number in list form, in reverse.

Returns the digits of a positive integer as a Maybe list, in reverse order or Nothing if a zero or negative base is given This is slightly more efficient than in forward order.

digitsRev #

Arguments

:: Integral n |
=> n | The base to use.
-> n | The number to convert to digit from.
-> [n] | The digits of the number in list from, in reverse.

Returns the digits of a positive integer as a list, in reverse order. Throws an error if given a zero or negative base.

unDigits #

Arguments

:: Integral n |
=> n | The base to use.
-> [n] | The digits of the number in list form.
-> n | The original number.

Takes a list of digits, and converts them back into a positive integer.

prop_digitsRoundTrip #

Arguments

:: Integer | The integer to test.
-> Integer | The base to use.
-> Property |

unDigits . digits should be the identity, in any positive base.