digits 0.3 → 0.3.1
raw patch · 2 files changed
+7/−8 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- digits.cabal +1/−1
- src/Data/Digits.hs +6/−7
digits.cabal view
@@ -1,7 +1,7 @@ Build-Type: Simple Name: digits Category: Data-Version: 0.3+Version: 0.3.1 Cabal-Version: >= 1.10 Synopsis: Converts integers to lists of digits and back. Description: Converts integers to lists of digits and back.
src/Data/Digits.hs view
@@ -5,25 +5,24 @@ import Data.List (genericTake) -- | Returns the digits of a positive integer as a Maybe list, in reverse order--- or Nothing if a negative base is given+-- or Nothing if a zero or negative base is given -- This is slightly more efficient than in forward order. mDigitsRev :: 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.-mDigitsRev base i = if base < 0- then Nothing -- We do not support negative bases+mDigitsRev base i = if base < 1+ then Nothing -- We do not support zero or negative bases else Just $ dr base i where dr _ 0 = [] dr b x = case base of- 0 -> [0] 1 -> genericTake x $ repeat 1 _ -> let (rest, lastDigit) = quotRem x b in lastDigit : dr b rest -- | Returns the digits of a positive integer as a Maybe list.--- or Nothing if a negative base is given+-- or Nothing if a zero or negative base is given mDigits :: Integral n => n -- ^ The base to use. -> n -- ^ The number to convert to digit form.@@ -31,7 +30,7 @@ mDigits base i = reverse <$> mDigitsRev base i -- | Returns the digits of a positive integer as a list, in reverse order.--- Throws an error if given a negative base.+-- Throws an error if given a zero or negative base. digitsRev :: Integral n => n -- ^ The base to use. -> n -- ^ The number to convert to digit from.@@ -39,7 +38,7 @@ digitsRev base = fromJust . mDigitsRev base -- | Returns the digits of a positive integer as a list.--- Throws an error if given a negative base.+-- Throws an error if given a zero or negative base. digits :: Integral n => n -- ^ The base to use (typically 10). -> n -- ^ The number to convert to digit form.