non-negative 0.0.4 → 0.0.5
raw patch · 3 files changed
+25/−10 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- non-negative.cabal +2/−2
- src/Numeric/NonNegative/Chunky.hs +4/−1
- src/Numeric/NonNegative/ChunkyPrivate.hs +19/−7
non-negative.cabal view
@@ -1,5 +1,5 @@ Name: non-negative-Version: 0.0.4+Version: 0.0.5 License: GPL License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -27,7 +27,7 @@ Library Build-Depends: QuickCheck >= 1.0 && <2 If flag(splitBase)- Build-Depends: base >= 2+ Build-Depends: base >= 2 && < 5 Else Build-Depends: base >= 1.0 && < 2
src/Numeric/NonNegative/Chunky.hs view
@@ -16,6 +16,9 @@ which allows for co-recursive merges. -} module Numeric.NonNegative.Chunky- (T, fromChunks, fromNumber, toChunks, toNumber, zero, normalize, isNull, isPositive, ) where+ (T, fromChunks, fromNumber, toChunks, toNumber,+ zero, normalize, isNull, isPositive,+ minMaxDiff,+ ) where import Numeric.NonNegative.ChunkyPrivate
src/Numeric/NonNegative/ChunkyPrivate.hs view
@@ -13,11 +13,13 @@ module Numeric.NonNegative.ChunkyPrivate (T, fromChunks, fromNumber, toChunks, toNumber, zero, normalize, isNull, isPositive,+ minMaxDiff, fromChunksUnsafe, toChunksUnsafe, ) where import qualified Numeric.NonNegative.Class as NonNeg import Control.Monad (liftM, liftM2) +import qualified Data.Monoid as Mn import Test.QuickCheck (Arbitrary(..)) {- |@@ -87,12 +89,6 @@ else error ("Numeric.NonNegative.Chunky."++funcName++": negative number") -{- |-In @glue x y == (z,r,b)@-@z@ represents @min x y@,-@r@ represents @max x y - min x y@,-and @x<y ==> b@ or @x>y ==> not b@, for @x==y@ the value of b is arbitrary.--} glue :: (NonNeg.C a) => [a] -> [a] -> ([a], [a], Bool) glue [] ys = ([], ys, True) glue xs [] = ([], xs, False)@@ -104,6 +100,18 @@ EQ -> (x, glue xs ys) in (z:zs,rs,b) +{- |+In @minMaxDiff x y == (z,r,b)@+@z@ represents @min x y@,+@r@ represents @max x y - min x y@,+and @x<y ==> b@ or @x>y ==> not b@,+ for @x==y@ the value of b is arbitrary.+-}+minMaxDiff :: (NonNeg.C a) => T a -> T a -> (T a, T a, Bool)+minMaxDiff (Cons xs) (Cons ys) =+ let (zs, rs, b) = glue xs ys+ in (Cons zs, Cons rs, b)+ equalList :: (NonNeg.C a) => [a] -> [a] -> Bool equalList x y = let (_,r,_) = glue x y@@ -142,7 +150,7 @@ in Cons (foldr sub x w) instance (NonNeg.C a) => Num (T a) where- (+) = lift2 (++)+ (+) = Mn.mappend (Cons x) - (Cons y) = let (_,d,b) = glue x y d' = Cons d@@ -153,6 +161,10 @@ abs = id signum = fromNumber . (\b -> if b then 1 else 0) . isPositive ++instance Mn.Monoid (T a) where+ mempty = zero+ mappend = lift2 (++) instance (NonNeg.C a, Arbitrary a) => Arbitrary (T a) where arbitrary = liftM Cons arbitrary