converge 0.1 → 0.1.0.1
raw patch · 2 files changed
+19/−6 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- converge.cabal +9/−2
- src/Math/Sequence/Converge.hs +10/−4
converge.cabal view
@@ -1,5 +1,5 @@ name: converge-version: 0.1+version: 0.1.0.1 stability: provisional cabal-version: >= 1.6@@ -14,10 +14,15 @@ synopsis: Limit operations for converging sequences description: Limit operations for converging sequences. This is fairly simple right now.+ .+ Changes in 0.1.0.1: Nothing except to enable -XSafe under+ GHC 7.2.1 tested-with: GHC == 6.8.3, GHC == 6.10.4,- GHC == 6.12.1, GHC == 6.12.3+ GHC == 6.12.1, GHC == 6.12.3,+ GHC == 7.0.4,+ GHC == 7.2.1 source-repository head type: darcs@@ -27,3 +32,5 @@ hs-source-dirs: src exposed-modules: Math.Sequence.Converge build-depends: base >= 3 && <5+ if impl(ghc >= 7.2)+ ghc-options: -trust base
src/Math/Sequence/Converge.hs view
@@ -1,3 +1,7 @@+{-# LANGUAGE CPP #-}+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Safe #-}+#endif module Math.Sequence.Converge where import Data.List@@ -10,9 +14,10 @@ -- pair is returned) . If the list ends before a match is found, -- returns the last element of the list. converge :: Eq a => [a] -> a-converge = fromMaybe empty . convergeBy eq Just+converge [] = error "converge: empty list"+converge xs = fromMaybe empty (convergeBy eq Just xs) where- empty = error "converge: empty list"+ empty = error "converge: programming error in converge implementation" eq (a:b:_) | a == b = Just b@@ -32,9 +37,10 @@ -- > phi :: Rational -- > phi = convergeTo 1e-100 0 (iterate (\x -> (x*x + 1) / (2*x-1)) 1) convergeTo :: (Fractional a, Ord a) => a -> a -> [a] -> a-convergeTo absEps relEps = fromMaybe empty . convergeBy eq Just+convergeTo absEps relEps [] = error "convergeTo: empty list"+convergeTo absEps relEps xs = fromMaybe empty (convergeBy eq Just xs) where- empty = error "convergeTo: empty list"+ empty = error "convergeTo: programming error in convergeTo implementation" eq (a:b:_) | b /= b = Just a | absDiff <= abs absEps = Just b