Skip to content

Commit 0e3634c

Browse files
authored
Merge pull request #78 from haskell/compatibility
Compatibility with future versions of GHC
2 parents 3694230 + e5a0b77 commit 0e3634c

File tree

6 files changed

+78
-77
lines changed

6 files changed

+78
-77
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,38 @@ jobs:
1818
matrix:
1919
include:
2020
# -- Linux --
21-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.0.2" }
22-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.2.2" }
23-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.4.4" }
24-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.6.5" }
25-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.8.4" }
26-
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.10.7" }
27-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.0.2" }
28-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.2.7" }
29-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5" }
30-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5", flags: "-system-erf" }
31-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5", flags: "-system-expm1"}
32-
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.6.2" }
21+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.0.2" }
22+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.2.2" }
23+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.4.4" }
24+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.6.5" }
25+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.8.4" }
26+
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.10.7" }
27+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.0.2" }
28+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.2.8" }
29+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8" }
30+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8", flags: "-system-erf" }
31+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8", flags: "-system-expm1"}
32+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.6.4" }
33+
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.8.2" }
3334
# -- Win --
34-
- { cabal: "3.6", os: windows-latest, ghc: "8.4.4" }
35-
- { cabal: "3.6", os: windows-latest, ghc: "8.6.5" }
36-
- { cabal: "3.6", os: windows-latest, ghc: "8.8.4" }
37-
- { cabal: "3.6", os: windows-latest, ghc: "8.10.4" }
38-
- { cabal: "3.6", os: windows-latest, ghc: "9.0.2" }
39-
- { cabal: "3.6", os: windows-latest, ghc: "9.2.7" }
40-
- { cabal: "3.6", os: windows-latest, ghc: "9.4.5" }
41-
- { cabal: "3.6", os: windows-latest, ghc: "9.6.2" }
35+
- { cabal: "3.10", os: windows-latest, ghc: "8.4.4" }
36+
- { cabal: "3.10", os: windows-latest, ghc: "8.6.5" }
37+
- { cabal: "3.10", os: windows-latest, ghc: "8.8.4" }
38+
- { cabal: "3.10", os: windows-latest, ghc: "8.10.7" }
39+
- { cabal: "3.10", os: windows-latest, ghc: "9.0.2" }
40+
- { cabal: "3.10", os: windows-latest, ghc: "9.2.8" }
41+
- { cabal: "3.10", os: windows-latest, ghc: "9.4.8" }
42+
- { cabal: "3.10", os: windows-latest, ghc: "9.6.4" }
43+
- { cabal: "3.10", os: windows-latest, ghc: "9.8.2" }
4244
# MacOS
43-
- { cabal: "3.6", os: macOS-latest, ghc: "8.4.4" }
44-
- { cabal: "3.6", os: macOS-latest, ghc: "8.6.5" }
45-
- { cabal: "3.6", os: macOS-latest, ghc: "8.8.4" }
46-
- { cabal: "3.6", os: macOS-latest, ghc: "8.10.4" }
47-
- { cabal: "3.6", os: macOS-latest, ghc: "9.2.7" }
48-
- { cabal: "3.6", os: macOS-latest, ghc: "9.4.5" }
49-
- { cabal: "3.6", os: macOS-latest, ghc: "9.6.2" }
45+
- { cabal: "3.10", os: macOS-latest, ghc: "8.4.4" }
46+
- { cabal: "3.10", os: macOS-latest, ghc: "8.6.5" }
47+
- { cabal: "3.10", os: macOS-latest, ghc: "8.8.4" }
48+
- { cabal: "3.10", os: macOS-latest, ghc: "8.10.7" }
49+
- { cabal: "3.10", os: macOS-latest, ghc: "9.2.8" }
50+
- { cabal: "3.10", os: macOS-latest, ghc: "9.4.8" }
51+
- { cabal: "3.10", os: macOS-latest, ghc: "9.6.4" }
52+
- { cabal: "3.10", os: macOS-latest, ghc: "9.8.2" }
5053
fail-fast: false
5154

5255
steps:

Numeric/RootFinding.hs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,31 @@ import Numeric.MathFunctions.Constants (m_epsilon)
5555
----------------------------------------------------------------
5656

5757
-- | The result of searching for a root of a mathematical function.
58-
data Root a = NotBracketed
59-
-- ^ The function does not have opposite signs when
60-
-- evaluated at the lower and upper bounds of the search.
61-
| SearchFailed
62-
-- ^ The search failed to converge to within the given
63-
-- error tolerance after the given number of iterations.
64-
| Root !a
65-
-- ^ A root was successfully found.
66-
deriving (Eq, Read, Show, Typeable, Data, Foldable, Traversable
67-
, Generic
68-
)
58+
data Root a
59+
= NotBracketed
60+
-- ^ The function does not have opposite signs when
61+
-- evaluated at the lower and upper bounds of the search.
62+
| SearchFailed
63+
-- ^ The search failed to converge to within the given
64+
-- error tolerance after the given number of iterations.
65+
| Root !a
66+
-- ^ A root was successfully found.
67+
deriving (Eq, Read, Show, Typeable, Data, Foldable, Traversable, Functor, Generic)
6968

7069
instance (NFData a) => NFData (Root a) where
7170
rnf NotBracketed = ()
7271
rnf SearchFailed = ()
7372
rnf (Root a) = rnf a
7473

75-
instance Functor Root where
76-
fmap _ NotBracketed = NotBracketed
77-
fmap _ SearchFailed = SearchFailed
78-
fmap f (Root a) = Root (f a)
79-
8074
instance Applicative Root where
81-
pure = return
75+
pure = Root
8276
(<*>) = ap
8377

8478
instance Monad Root where
8579
NotBracketed >>= _ = NotBracketed
8680
SearchFailed >>= _ = SearchFailed
8781
Root a >>= f = f a
88-
return = Root
82+
return = pure
8983

9084
instance MonadPlus Root where
9185
mzero = empty

Numeric/SpecFunctions/Internal.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module Numeric.SpecFunctions.Internal
1818

1919
import Data.Bits ((.&.), (.|.), shiftR)
2020
import Data.Int (Int64)
21-
import Data.Word (Word)
2221
import Data.Default.Class
2322
import qualified Data.Vector.Unboxed as U
2423
import Data.Vector.Unboxed ((!))

Numeric/Sum.hs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ import Control.Arrow ((***))
5353
import Control.DeepSeq (NFData(..))
5454
import Data.Bits (shiftR)
5555
import Data.Data (Typeable, Data)
56-
import Data.Semigroup (Semigroup(..))
56+
import Data.Semigroup (Semigroup(..)) -- Needed for GHC <8.4
5757
import Data.Vector.Generic (Vector(..))
58-
-- Needed for GHC 7.2 & 7.4 to derive Unbox instances
59-
import Control.Monad (liftM)
6058
import Data.Vector.Generic.Mutable (MVector(..))
6159

6260
import qualified Data.Foldable as F
@@ -115,16 +113,16 @@ instance MVector U.MVector KahanSum where
115113
basicLength (MV_KahanSum mvec) = GM.basicLength mvec
116114
basicUnsafeSlice idx len (MV_KahanSum mvec) = MV_KahanSum (GM.basicUnsafeSlice idx len mvec)
117115
basicOverlaps (MV_KahanSum mvec) (MV_KahanSum mvec') = basicOverlaps mvec mvec'
118-
basicUnsafeNew len = MV_KahanSum `liftM` basicUnsafeNew len
116+
basicUnsafeNew len = MV_KahanSum <$> basicUnsafeNew len
119117
basicInitialize (MV_KahanSum mvec) = basicInitialize mvec
120-
basicUnsafeReplicate len val = MV_KahanSum `liftM` basicUnsafeReplicate len ((\ (KahanSum a b) -> (a, b)) val)
121-
basicUnsafeRead (MV_KahanSum mvec) idx = (\ (a, b) -> KahanSum a b) `liftM` basicUnsafeRead mvec idx
118+
basicUnsafeReplicate len val = MV_KahanSum <$> basicUnsafeReplicate len ((\ (KahanSum a b) -> (a, b)) val)
119+
basicUnsafeRead (MV_KahanSum mvec) idx = (\ (a, b) -> KahanSum a b) <$> basicUnsafeRead mvec idx
122120
basicUnsafeWrite (MV_KahanSum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KahanSum a b) -> (a, b)) val)
123121
basicClear (MV_KahanSum mvec) = basicClear mvec
124122
basicSet (MV_KahanSum mvec) val = basicSet mvec ((\ (KahanSum a b) -> (a, b)) val)
125123
basicUnsafeCopy (MV_KahanSum mvec) (MV_KahanSum mvec') = GM.basicUnsafeCopy mvec mvec'
126124
basicUnsafeMove (MV_KahanSum mvec) (MV_KahanSum mvec') = basicUnsafeMove mvec mvec'
127-
basicUnsafeGrow (MV_KahanSum mvec) len = MV_KahanSum `liftM` basicUnsafeGrow mvec len
125+
basicUnsafeGrow (MV_KahanSum mvec) len = MV_KahanSum <$> basicUnsafeGrow mvec len
128126

129127
newtype instance U.Vector KahanSum = V_KahanSum (U.Vector (Double, Double))
130128
instance Vector U.Vector KahanSum where
@@ -135,11 +133,11 @@ instance Vector U.Vector KahanSum where
135133
{-# INLINE basicUnsafeIndexM #-}
136134
{-# INLINE G.basicUnsafeCopy #-}
137135
{-# INLINE elemseq #-}
138-
basicUnsafeFreeze (MV_KahanSum mvec) = V_KahanSum `liftM` basicUnsafeFreeze mvec
139-
basicUnsafeThaw (V_KahanSum vec) = MV_KahanSum `liftM` basicUnsafeThaw vec
136+
basicUnsafeFreeze (MV_KahanSum mvec) = V_KahanSum <$> basicUnsafeFreeze mvec
137+
basicUnsafeThaw (V_KahanSum vec) = MV_KahanSum <$> basicUnsafeThaw vec
140138
basicLength (V_KahanSum vec) = G.basicLength vec
141139
basicUnsafeSlice idx len (V_KahanSum vec) = V_KahanSum (G.basicUnsafeSlice idx len vec)
142-
basicUnsafeIndexM (V_KahanSum vec) idx = (\ (a, b) -> KahanSum a b) `liftM` basicUnsafeIndexM vec idx
140+
basicUnsafeIndexM (V_KahanSum vec) idx = (\ (a, b) -> KahanSum a b) <$> basicUnsafeIndexM vec idx
143141
basicUnsafeCopy (MV_KahanSum mvec) (V_KahanSum vec) = G.basicUnsafeCopy mvec vec
144142
elemseq (V_KahanSum vec) val = elemseq vec ((\ (KahanSum a b) -> (a, b)) val)
145143

@@ -154,11 +152,11 @@ instance NFData KahanSum where
154152
-- | @since 0.3.0.0
155153
instance Monoid KahanSum where
156154
mempty = zero
157-
s `mappend` KahanSum s' _ = add s s'
155+
mappend = (<>)
158156

159157
-- | @since 0.3.0.0
160158
instance Semigroup KahanSum where
161-
(<>) = mappend
159+
s <> KahanSum s' _ = add s s'
162160

163161
kahanAdd :: KahanSum -> Double -> KahanSum
164162
kahanAdd (KahanSum sum c) x = KahanSum sum' c'
@@ -195,16 +193,16 @@ instance MVector U.MVector KBNSum where
195193
basicLength (MV_KBNSum mvec) = GM.basicLength mvec
196194
basicUnsafeSlice idx len (MV_KBNSum mvec) = MV_KBNSum (GM.basicUnsafeSlice idx len mvec)
197195
basicOverlaps (MV_KBNSum mvec) (MV_KBNSum mvec') = basicOverlaps mvec mvec'
198-
basicUnsafeNew len = MV_KBNSum `liftM` basicUnsafeNew len
196+
basicUnsafeNew len = MV_KBNSum <$> basicUnsafeNew len
199197
basicInitialize (MV_KBNSum mvec) = basicInitialize mvec
200-
basicUnsafeReplicate len val = MV_KBNSum `liftM` basicUnsafeReplicate len ((\ (KBNSum a b) -> (a, b)) val)
201-
basicUnsafeRead (MV_KBNSum mvec) idx = (\ (a, b) -> KBNSum a b) `liftM` basicUnsafeRead mvec idx
198+
basicUnsafeReplicate len val = MV_KBNSum <$> basicUnsafeReplicate len ((\ (KBNSum a b) -> (a, b)) val)
199+
basicUnsafeRead (MV_KBNSum mvec) idx = (\ (a, b) -> KBNSum a b) <$> basicUnsafeRead mvec idx
202200
basicUnsafeWrite (MV_KBNSum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KBNSum a b) -> (a, b)) val)
203201
basicClear (MV_KBNSum mvec) = basicClear mvec
204202
basicSet (MV_KBNSum mvec) val = basicSet mvec ((\ (KBNSum a b) -> (a, b)) val)
205203
basicUnsafeCopy (MV_KBNSum mvec) (MV_KBNSum mvec') = GM.basicUnsafeCopy mvec mvec'
206204
basicUnsafeMove (MV_KBNSum mvec) (MV_KBNSum mvec') = basicUnsafeMove mvec mvec'
207-
basicUnsafeGrow (MV_KBNSum mvec) len = MV_KBNSum `liftM` basicUnsafeGrow mvec len
205+
basicUnsafeGrow (MV_KBNSum mvec) len = MV_KBNSum <$> basicUnsafeGrow mvec len
208206

209207
newtype instance U.Vector KBNSum = V_KBNSum (U.Vector (Double, Double))
210208
instance Vector U.Vector KBNSum where
@@ -215,11 +213,11 @@ instance Vector U.Vector KBNSum where
215213
{-# INLINE basicUnsafeIndexM #-}
216214
{-# INLINE G.basicUnsafeCopy #-}
217215
{-# INLINE elemseq #-}
218-
basicUnsafeFreeze (MV_KBNSum mvec) = V_KBNSum `liftM` basicUnsafeFreeze mvec
219-
basicUnsafeThaw (V_KBNSum vec) = MV_KBNSum `liftM` basicUnsafeThaw vec
216+
basicUnsafeFreeze (MV_KBNSum mvec) = V_KBNSum <$> basicUnsafeFreeze mvec
217+
basicUnsafeThaw (V_KBNSum vec) = MV_KBNSum <$> basicUnsafeThaw vec
220218
basicLength (V_KBNSum vec) = G.basicLength vec
221219
basicUnsafeSlice idx len (V_KBNSum vec) = V_KBNSum (G.basicUnsafeSlice idx len vec)
222-
basicUnsafeIndexM (V_KBNSum vec) idx = (\ (a, b) -> KBNSum a b) `liftM` basicUnsafeIndexM vec idx
220+
basicUnsafeIndexM (V_KBNSum vec) idx = (\ (a, b) -> KBNSum a b) <$> basicUnsafeIndexM vec idx
223221
basicUnsafeCopy (MV_KBNSum mvec) (V_KBNSum vec) = G.basicUnsafeCopy mvec vec
224222
elemseq (V_KBNSum vec) val = elemseq vec ((\ (KBNSum a b) -> (a, b)) val)
225223

@@ -234,11 +232,12 @@ instance NFData KBNSum where
234232
-- | @since 0.3.0.0
235233
instance Monoid KBNSum where
236234
mempty = zero
237-
s `mappend` KBNSum s' c' = add (add s s') c'
235+
mappend = (<>)
238236

239237
-- | @since 0.3.0.0
240238
instance Semigroup KBNSum where
241-
(<>) = mappend
239+
s <> KBNSum s' c' = add (add s s') c'
240+
242241

243242
kbnAdd :: KBNSum -> Double -> KBNSum
244243
kbnAdd (KBNSum sum c) x = KBNSum sum' c'
@@ -282,16 +281,16 @@ instance MVector U.MVector KB2Sum where
282281
basicLength (MV_KB2Sum mvec) = GM.basicLength mvec
283282
basicUnsafeSlice idx len (MV_KB2Sum mvec) = MV_KB2Sum (GM.basicUnsafeSlice idx len mvec)
284283
basicOverlaps (MV_KB2Sum mvec) (MV_KB2Sum mvec') = basicOverlaps mvec mvec'
285-
basicUnsafeNew len = MV_KB2Sum `liftM` basicUnsafeNew len
284+
basicUnsafeNew len = MV_KB2Sum <$> basicUnsafeNew len
286285
basicInitialize (MV_KB2Sum mvec) = basicInitialize mvec
287-
basicUnsafeReplicate len val = MV_KB2Sum `liftM` basicUnsafeReplicate len ((\ (KB2Sum a b c) -> (a, b, c)) val)
288-
basicUnsafeRead (MV_KB2Sum mvec) idx = (\ (a, b, c) -> KB2Sum a b c) `liftM` basicUnsafeRead mvec idx
286+
basicUnsafeReplicate len val = MV_KB2Sum <$> basicUnsafeReplicate len ((\ (KB2Sum a b c) -> (a, b, c)) val)
287+
basicUnsafeRead (MV_KB2Sum mvec) idx = (\ (a, b, c) -> KB2Sum a b c) <$> basicUnsafeRead mvec idx
289288
basicUnsafeWrite (MV_KB2Sum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KB2Sum a b c) -> (a, b, c)) val)
290289
basicClear (MV_KB2Sum mvec) = basicClear mvec
291290
basicSet (MV_KB2Sum mvec) val = basicSet mvec ((\ (KB2Sum a b c) -> (a, b, c)) val)
292291
basicUnsafeCopy (MV_KB2Sum mvec) (MV_KB2Sum mvec') = GM.basicUnsafeCopy mvec mvec'
293292
basicUnsafeMove (MV_KB2Sum mvec) (MV_KB2Sum mvec') = basicUnsafeMove mvec mvec'
294-
basicUnsafeGrow (MV_KB2Sum mvec) len = MV_KB2Sum `liftM` basicUnsafeGrow mvec len
293+
basicUnsafeGrow (MV_KB2Sum mvec) len = MV_KB2Sum <$> basicUnsafeGrow mvec len
295294

296295
newtype instance U.Vector KB2Sum = V_KB2Sum (U.Vector (Double, Double, Double))
297296
instance Vector U.Vector KB2Sum where
@@ -302,11 +301,11 @@ instance Vector U.Vector KB2Sum where
302301
{-# INLINE basicUnsafeIndexM #-}
303302
{-# INLINE G.basicUnsafeCopy #-}
304303
{-# INLINE elemseq #-}
305-
basicUnsafeFreeze (MV_KB2Sum mvec) = V_KB2Sum `liftM` basicUnsafeFreeze mvec
306-
basicUnsafeThaw (V_KB2Sum vec) = MV_KB2Sum `liftM` basicUnsafeThaw vec
304+
basicUnsafeFreeze (MV_KB2Sum mvec) = V_KB2Sum <$> basicUnsafeFreeze mvec
305+
basicUnsafeThaw (V_KB2Sum vec) = MV_KB2Sum <$> basicUnsafeThaw vec
307306
basicLength (V_KB2Sum vec) = G.basicLength vec
308307
basicUnsafeSlice idx len (V_KB2Sum vec) = V_KB2Sum (G.basicUnsafeSlice idx len vec)
309-
basicUnsafeIndexM (V_KB2Sum vec) idx = (\ (a, b, c) -> KB2Sum a b c) `liftM` basicUnsafeIndexM vec idx
308+
basicUnsafeIndexM (V_KB2Sum vec) idx = (\ (a, b, c) -> KB2Sum a b c) <$> basicUnsafeIndexM vec idx
310309
basicUnsafeCopy (MV_KB2Sum mvec) (V_KB2Sum vec) = G.basicUnsafeCopy mvec vec
311310
elemseq (V_KB2Sum vec) val = elemseq vec ((\ (KB2Sum a b c) -> (a, b, c)) val)
312311

@@ -320,11 +319,11 @@ instance NFData KB2Sum where
320319
-- | @since 0.3.0.0
321320
instance Monoid KB2Sum where
322321
mempty = zero
323-
s `mappend` KB2Sum s' c' cc' = add (add (add s s') c') cc'
322+
mappend = (<>)
324323

325324
-- | @since 0.3.0.0
326325
instance Semigroup KB2Sum where
327-
(<>) = mappend
326+
s <> KB2Sum s' c' cc' = add (add (add s s') c') cc'
328327

329328

330329
kb2Add :: KB2Sum -> Double -> KB2Sum

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Changes in 0.3.4.4
2+
3+
* Support for future versions of GHC. Monoid and Monad instances now have
4+
canonical form
5+
6+
17
## Changes in 0.3.4.3
28

39
* Support for `QuickCheck >= 2.14`. Test no longer fail

math-functions.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: math-functions
2-
version: 0.3.4.3
2+
version: 0.3.4.4
33
cabal-version: >= 1.10
44
license: BSD2
55
license-file: LICENSE

0 commit comments

Comments
 (0)