numbers 2008.4.20.1 → 2009.5.18.1
raw patch · 2 files changed
+17/−4 lines, 2 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Number/Natural.hs +16/−3
- numbers.cabal +1/−1
Data/Number/Natural.hs view
@@ -6,6 +6,8 @@ -- when considering bottom. module Data.Number.Natural(Natural, infinity) where +import Data.Maybe+ data Natural = Z | S Natural instance Show Natural where@@ -20,13 +22,16 @@ S _ `compare` Z = GT S x `compare` S y = x `compare` y +maybeSubtract :: Natural -> Natural -> Maybe Natural+a `maybeSubtract` Z = Just a+S a `maybeSubtract` S b = a `maybeSubtract` b+_ `maybeSubtract` _ = Nothing+ instance Num Natural where Z + y = y S x + y = S (x + y) - x - Z = x- Z - S _ = error "Natural: (-)"- S x - S y = x - y+ x - y = fromMaybe (error "Natural: (-)") (x `maybeSubtract` y) Z * y = Z S x * y = y + x * y@@ -56,8 +61,16 @@ toRational = toRational . toInteger instance Enum Natural where+ succ = (+1)+ pred = (subtract 1) toEnum = fromIntegral fromEnum = fromIntegral+ enumFromThenTo from thn to = go from (to `maybeSubtract` from) where+ go from Nothing = []+ go from (Just count) = from:go (thn + from) (count `maybeSubtract` thn)+ enumFrom a = enumFromThenTo a 1 infinity+ enumFromThen a b = enumFromThenTo a b infinity+ enumFromTo a c = enumFromThenTo a 1 c -- | The infinite natural number. infinity :: Natural
numbers.cabal view
@@ -1,5 +1,5 @@ Name: numbers-Version: 2008.4.20.1+Version: 2009.5.18.1 License: BSD3 Author: Lennart Augustsson Maintainer: Lennart Augustsson