haskell / math-functions

Special mathematical functions
http://hackage.haskell.org/package/math-functions
BSD 2-Clause "Simplified" License
40 stars 28 forks source link

Remove TemplateHaskell usage #61

Closed phadej closed 4 years ago

phadej commented 4 years ago

I -ddump-splices and cleaned up the names (simple regexp) and extra parenthesis.

This allows to drop vector-th-unbox dependency, and make math-functions buildable with GHC without TH (or broken one, like some development versions).

Shimuuar commented 4 years ago

Thanks! Uploaded as 0.3.4.0

P.S. Working with unboxed data is such gaping hole in the language. I wish it was possible to put value into unboxed vector without writing 50 LoC

RyanGlScott commented 4 years ago

I think this change demands that the lower version bounds on vector be raised. This code mentions basicInitialize, which was first introduced in vector-0.11.0.0. However, math-functions-0.3.4.0' lower bounds on vector are currently >= 0.7. This can lead to failing build plans with older versions of vector:

``` $ cabal install math-functions -w /opt/ghc/8.2.2/bin/ghc --constraint="math-functions==0.3.3.0" --constraint="vector==0.10.*" # Succeeds $ cabal install math-functions -w /opt/ghc/8.2.2/bin/ghc --constraint="math-functions==0.3.4.0" --constraint="vector==0.10.*" Resolving dependencies... Build profile: -w ghc-8.2.2 -O1 In order, the following will be built (use -v for more details): - math-functions-0.3.4.0 (lib) (requires build) Starting math-functions-0.3.4.0 (lib) Building math-functions-0.3.4.0 (lib) Failed to build math-functions-0.3.4.0. Build log ( /home/rgscott/.cabal/logs/ghc-8.2.2/math-functions-0.3.4.0-067348450dfff6c1af662e66bd42c084dcb16732ee8b35a423dfcb7957d3fe81.log ): Configuring library for math-functions-0.3.4.0.. Preprocessing library for math-functions-0.3.4.0.. Building library for math-functions-0.3.4.0.. [ 1 of 11] Compiling Numeric.MathFunctions.Comparison ( Numeric/MathFunctions/Comparison.hs, dist/build/Numeric/MathFunctions/Comparison.o ) [ 2 of 11] Compiling Numeric.MathFunctions.Constants ( Numeric/MathFunctions/Constants.hs, dist/build/Numeric/MathFunctions/Constants.o ) [ 3 of 11] Compiling Numeric.Polynomial ( Numeric/Polynomial.hs, dist/build/Numeric/Polynomial.o ) [ 4 of 11] Compiling Numeric.Polynomial.Chebyshev ( Numeric/Polynomial/Chebyshev.hs, dist/build/Numeric/Polynomial/Chebyshev.o ) [ 5 of 11] Compiling Numeric.RootFinding ( Numeric/RootFinding.hs, dist/build/Numeric/RootFinding.o ) Numeric/RootFinding.hs:47:1: warning: [-Wunused-imports] The import of ‘Data.Monoid’ is redundant except perhaps to import instances from ‘Data.Monoid’ To import instances alone, use: import Data.Monoid() | 47 | import Data.Monoid (Monoid(..)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [ 6 of 11] Compiling Numeric.Series ( Numeric/Series.hs, dist/build/Numeric/Series.o ) [ 7 of 11] Compiling Numeric.SpecFunctions.Compat ( Numeric/SpecFunctions/Compat.hs, dist/build/Numeric/SpecFunctions/Compat.o ) Numeric/SpecFunctions/Compat.hs:12:1: warning: [-Wunused-imports] The import of ‘Control.Applicative’ is redundant except perhaps to import instances from ‘Control.Applicative’ To import instances alone, use: import Control.Applicative() | 12 | import Control.Applicative | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Numeric/SpecFunctions/Compat.hs:13:1: warning: [-Wunused-imports] The qualified import of ‘Data.Vector.Unboxed’ is redundant except perhaps to import instances from ‘Data.Vector.Unboxed’ To import instances alone, use: import Data.Vector.Unboxed() | 13 | import qualified Data.Vector.Unboxed as U | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Numeric/SpecFunctions/Compat.hs:14:1: warning: [-Wunused-imports] The import of ‘Numeric.MathFunctions.Constants’ is redundant except perhaps to import instances from ‘Numeric.MathFunctions.Constants’ To import instances alone, use: import Numeric.MathFunctions.Constants() | 14 | import Numeric.MathFunctions.Constants | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Numeric/SpecFunctions/Compat.hs:15:1: warning: [-Wunused-imports] The import of ‘Numeric.Polynomial.Chebyshev’ is redundant except perhaps to import instances from ‘Numeric.Polynomial.Chebyshev’ To import instances alone, use: import Numeric.Polynomial.Chebyshev() | 15 | import Numeric.Polynomial.Chebyshev (chebyshev,chebyshevBroucke) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Numeric/SpecFunctions/Compat.hs:16:1: warning: [-Wunused-imports] The import of ‘Numeric.Polynomial’ is redundant except perhaps to import instances from ‘Numeric.Polynomial’ To import instances alone, use: import Numeric.Polynomial() | 16 | import Numeric.Polynomial (evaluateOddPolynomial) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Numeric/SpecFunctions/Compat.hs:17:1: warning: [-Wunused-imports] The import of ‘Numeric.Series’ is redundant except perhaps to import instances from ‘Numeric.Series’ To import instances alone, use: import Numeric.Series() | 17 | import Numeric.Series | ^^^^^^^^^^^^^^^^^^^^^ [ 8 of 11] Compiling Numeric.SpecFunctions.Internal ( Numeric/SpecFunctions/Internal.hs, dist/build/Numeric/SpecFunctions/Internal.o ) Numeric/SpecFunctions/Internal.hs:19:1: warning: [-Wunused-imports] The import of ‘Control.Applicative’ is redundant except perhaps to import instances from ‘Control.Applicative’ To import instances alone, use: import Control.Applicative() | 19 | import Control.Applicative | ^^^^^^^^^^^^^^^^^^^^^^^^^^ [ 9 of 11] Compiling Numeric.SpecFunctions.Extra ( Numeric/SpecFunctions/Extra.hs, dist/build/Numeric/SpecFunctions/Extra.o ) [10 of 11] Compiling Numeric.SpecFunctions ( Numeric/SpecFunctions.hs, dist/build/Numeric/SpecFunctions.o ) [11 of 11] Compiling Numeric.Sum ( Numeric/Sum.hs, dist/build/Numeric/Sum.o ) Numeric/Sum.hs:109:14: error: The INLINE pragma for ‘basicInitialize’ lacks an accompanying binding | 109 | {-# INLINE basicInitialize #-} | ^^^^^^^^^^^^^^^ Numeric/Sum.hs:122:3: error: ‘basicInitialize’ is not a (visible) method of class ‘MVector’ | 122 | basicInitialize (MV_KahanSum mvec) = basicInitialize mvec | ^^^^^^^^^^^^^^^ Numeric/Sum.hs:191:14: error: The INLINE pragma for ‘basicInitialize’ lacks an accompanying binding | 191 | {-# INLINE basicInitialize #-} | ^^^^^^^^^^^^^^^ Numeric/Sum.hs:204:3: error: ‘basicInitialize’ is not a (visible) method of class ‘MVector’ | 204 | basicInitialize (MV_KBNSum mvec) = basicInitialize mvec | ^^^^^^^^^^^^^^^ Numeric/Sum.hs:280:14: error: The INLINE pragma for ‘basicInitialize’ lacks an accompanying binding | 280 | {-# INLINE basicInitialize #-} | ^^^^^^^^^^^^^^^ Numeric/Sum.hs:293:3: error: ‘basicInitialize’ is not a (visible) method of class ‘MVector’ | 293 | basicInitialize (MV_KB2Sum mvec) = basicInitialize mvec | ^^^^^^^^^^^^^^^ cabal: Failed to build math-functions-0.3.4.0. See the build log above for details. ```

I think all that would need to be done to address this is to make the following change to vector.cabal:

diff --git a/math-functions.cabal b/math-functions.cabal
index a708c6e..6f47e3c 100644
--- a/math-functions.cabal
+++ b/math-functions.cabal
@@ -74,7 +74,7 @@ library
   build-depends:        base                >= 4.5 && < 5
                       , deepseq
                       , data-default-class  >= 0.1.2.0
-                      , vector              >= 0.7
+                      , vector              >= 0.11
                       , primitive
   if flag(system-expm1) && !os(windows)
     cpp-options: -DUSE_SYSTEM_EXPM1

Alternatively, older versions of vector could be supported by guarding uses of basicInitialize with #if MIN_VERSION_vector(0,11,0) ... #endif. (This is the approach that vector-th-unbox takes.)

phadej commented 4 years ago

@RyanGlScott thanks for mentioning! I'll do the revision asap.

I'd recommend just raising lower vector bound. As there are virtually no problems with updating code to use it. (I'd actually be happy if people not used old vector versions).

Shimuuar commented 4 years ago

I've amended vector's version bound on hackage and updated master. Vector 0.7 belongs to software archeology not software development

phadej commented 4 years ago

@Shimuuar thanks!