haskell / math-functions

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

Numeric/Sum.hs:97:1: error: Expecting a type of the form: cxts => typ -> rep on Fedora 26 #52

Closed atodorov closed 6 years ago

atodorov commented 6 years ago

On a Fedora 26 system I did:

1) dnf install cabal-install 2) cabal sandbox init 3) cabal update 4) cabal install math-functions

and I got the following error:

cabal: Entering directory '/tmp/cabal-tmp-1420/math-functions-0.2.1.0'
Configuring math-functions-0.2.1.0...
Building math-functions-0.2.1.0...
Preprocessing library math-functions-0.2.1.0...
[ 1 of 10] Compiling Numeric.Sum      ( Numeric/Sum.hs, dist/dist-sandbox-1e35363/build/Numeric/Sum.o )

Numeric/Sum.hs:97:1: error:
    Expecting a type of the form: cxts => typ -> rep
cabal: Leaving directory '/tmp/cabal-tmp-1420/math-functions-0.2.1.0'

$ ghc --version The Glorious Glasgow Haskell Compilation System, version 8.0.2

I'm not sure why this fails but it is blocking my CI build. Can you give me some tips how to figure out what's going on ?

update: the offending code is

     94 data KahanSum = KahanSum {-# UNPACK #-} !Double {-# UNPACK #-} !Double
     95               deriving (Eq, Show, Typeable, Data)
     96 
     97 derivingUnbox "KahanSum"
     98     [t| KahanSum -> (Double, Double) |]
     99     [| \ (KahanSum a b) -> (a, b) |]
    100     [| \ (a, b) -> KahanSum a b |]
atodorov commented 6 years ago

FYI if I install the following two RPMs (not yet part of the Fedora repos) https://kojipkgs.fedoraproject.org//packages/ghc-vector-th-unbox/0.2.1.6/1.fc26/x86_64/ghc-vector-th-unbox-0.2.1.6-1.fc26.x86_64.rpm https://kojipkgs.fedoraproject.org//packages/ghc-vector-th-unbox/0.2.1.6/1.fc26/x86_64/ghc-vector-th-unbox-devel-0.2.1.6-1.fc26.x86_64.rpm

then I'm able to build. Looking at what cabal fetches from hackage.haskell.org it appears that vector-th-unbox has exectly the same version so I have no idea why that fails.

@clumens: ^^^ fyi

clumens commented 6 years ago

Did installing the RPM bring in some dependencies that installing from cabal did not? This is template haskell stuff, so other modules and processes are involved in producing the code that gets compiled (or not).

Shimuuar commented 6 years ago

This is really weird error Expecting a type of the form: cxts => typ -> rep is error message from vector-th-unbox. It suggests that for some reason type quotation does not have form ArrowT ``AppT`` typ ``AppT`` rep. Thy it happens I have no idea

atodorov commented 6 years ago

From what I can see there are a few differences in versions but the dependency list is the same. There is a difference in the version for ghc-boot-th and template-haskell and a few others.

Log of building with dependencies coming from hackage.haskell.org:

# cabal sandbox init
Config file path source is default config file.
Config file /root/.cabal/config not found.
Writing default configuration to /root/.cabal/config
Writing a default package environment file to
/tmp/math-functions/cabal.sandbox.config
Creating a new sandbox at /tmp/math-functions/.cabal-sandbox

[root@25721b8f2a36 math-functions]# cabal update
Downloading the latest package list from hackage.haskell.org

[root@25721b8f2a36 math-functions]# cabal install --dependencies-only
Resolving dependencies...
Notice: installing into a sandbox located at
/tmp/math-functions/.cabal-sandbox
Downloading ghc-boot-th-8.2.2...
Downloading transformers-0.5.5.0...
Configuring ghc-boot-th-8.2.2...
Configuring transformers-0.5.5.0...
Building ghc-boot-th-8.2.2...
Building transformers-0.5.5.0...
Installed ghc-boot-th-8.2.2
Downloading template-haskell-2.12.0.0...
Configuring template-haskell-2.12.0.0...
Building template-haskell-2.12.0.0...
Installed transformers-0.5.5.0
Downloading primitive-0.6.2.0...
Configuring primitive-0.6.2.0...
Building primitive-0.6.2.0...
Installed primitive-0.6.2.0
Downloading vector-0.12.0.1...
Configuring vector-0.12.0.1...
Building vector-0.12.0.1...
Installed template-haskell-2.12.0.0
Installed vector-0.12.0.1
Downloading vector-th-unbox-0.2.1.6...
Configuring vector-th-unbox-0.2.1.6...
Building vector-th-unbox-0.2.1.6...
Installed vector-th-unbox-0.2.1.6

[root@25721b8f2a36 math-functions]# cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring math-functions-0.2.1.0...
Building math-functions-0.2.1.0...
Preprocessing library math-functions-0.2.1.0...
[ 1 of 10] Compiling Numeric.Sum      ( Numeric/Sum.hs, dist/build/Numeric/Sum.o )

Numeric/Sum.hs:97:1: error:
    Expecting a type of the form: cxts => typ -> rep
[ 2 of 10] Compiling Numeric.Polynomial.Chebyshev ( Numeric/Polynomial/Chebyshev.hs, dist/build/Numeric/Polynomial/Chebyshev.o )
[ 3 of 10] Compiling Numeric.Polynomial ( Numeric/Polynomial.hs, dist/build/Numeric/Polynomial.o )
[ 4 of 10] Compiling Numeric.MathFunctions.Constants ( Numeric/MathFunctions/Constants.hs, dist/build/Numeric/MathFunctions/Constants.o )
[ 5 of 10] Compiling Numeric.Series   ( Numeric/Series.hs, dist/build/Numeric/Series.o )
[ 6 of 10] Compiling Numeric.MathFunctions.Comparison ( Numeric/MathFunctions/Comparison.hs, dist/build/Numeric/MathFunctions/Comparison.o )
[ 7 of 10] Compiling Numeric.RootFinding ( Numeric/RootFinding.hs, dist/build/Numeric/RootFinding.o )
[ 8 of 10] Compiling Numeric.SpecFunctions.Internal ( Numeric/SpecFunctions/Internal.hs, dist/build/Numeric/SpecFunctions/Internal.o )

Numeric/SpecFunctions/Internal.hs:24:1: warning: [-Wunused-imports]
    The import of `expm1' from module `GHC.Float' is redundant
[ 9 of 10] Compiling Numeric.SpecFunctions ( Numeric/SpecFunctions.hs, dist/build/Numeric/SpecFunctions.o )
[10 of 10] Compiling Numeric.SpecFunctions.Extra ( Numeric/SpecFunctions/Extra.hs, dist/build/Numeric/SpecFunctions/Extra.o )

[root@25721b8f2a36 math-functions]# echo $?
1

log from building with dependencies coming from RPM:

# dnf install ghc-vector-th-unbox-*
Last metadata expiration check: 5:38:50 ago on Wed Dec  6 09:08:54 2017.
Dependencies resolved.
==========================================================================================================================================
 Package                                    Arch                   Version                             Repository                    Size
==========================================================================================================================================
Installing:
 ghc-vector-th-unbox                        x86_64                 0.2.1.6-1.fc26                      @commandline                  22 k
 ghc-vector-th-unbox-devel                  x86_64                 0.2.1.6-1.fc26                      @commandline                  69 k
Installing dependencies:
 ghc-ghc-boot-th-devel                      x86_64                 8.0.2-57.fc26                       fedora                       194 k
 ghc-primitive                              x86_64                 0.6.1.0-3.fc26                      fedora                        45 k
 ghc-primitive-devel                        x86_64                 0.6.1.0-3.fc26                      fedora                       141 k
 ghc-template-haskell-devel                 x86_64                 2.11.1.0-57.fc26                    fedora                       2.0 M
 ghc-transformers-devel                     x86_64                 0.5.2.0-57.fc26                     fedora                       882 k
 ghc-vector                                 x86_64                 0.11.0.0-3.fc26                     fedora                       517 k
 ghc-vector-devel                           x86_64                 0.11.0.0-3.fc26                     fedora                       1.9 M

Transaction Summary
==========================================================================================================================================
Install  9 Packages

Total size: 5.7 M
Total download size: 5.6 M
Installed size: 94 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): ghc-primitive-0.6.1.0-3.fc26.x86_64.rpm                                                            111 kB/s |  45 kB     00:00    
(2/7): ghc-vector-0.11.0.0-3.fc26.x86_64.rpm                                                              1.0 MB/s | 517 kB     00:00    
(3/7): ghc-ghc-boot-th-devel-8.0.2-57.fc26.x86_64.rpm                                                     1.3 MB/s | 194 kB     00:00    
(4/7): ghc-primitive-devel-0.6.1.0-3.fc26.x86_64.rpm                                                      1.1 MB/s | 141 kB     00:00    
(5/7): ghc-vector-devel-0.11.0.0-3.fc26.x86_64.rpm                                                        2.6 MB/s | 1.9 MB     00:00    
(6/7): ghc-transformers-devel-0.5.2.0-57.fc26.x86_64.rpm                                                  1.1 MB/s | 882 kB     00:00    
(7/7): ghc-template-haskell-devel-2.11.1.0-57.fc26.x86_64.rpm                                             1.3 MB/s | 2.0 MB     00:01    
------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                     2.3 MB/s | 5.6 MB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                  1/1 
  Installing       : ghc-primitive-0.6.1.0-3.fc26.x86_64                                                                              1/9 
  Installing       : ghc-vector-0.11.0.0-3.fc26.x86_64                                                                                2/9 
  Installing       : ghc-vector-th-unbox-0.2.1.6-1.fc26.x86_64                                                                        3/9 
  Installing       : ghc-transformers-devel-0.5.2.0-57.fc26.x86_64                                                                    4/9 
  Running scriptlet: ghc-transformers-devel-0.5.2.0-57.fc26.x86_64                                                                    4/9 
  Installing       : ghc-primitive-devel-0.6.1.0-3.fc26.x86_64                                                                        5/9 
  Running scriptlet: ghc-primitive-devel-0.6.1.0-3.fc26.x86_64                                                                        5/9 
  Installing       : ghc-vector-devel-0.11.0.0-3.fc26.x86_64                                                                          6/9 
  Running scriptlet: ghc-vector-devel-0.11.0.0-3.fc26.x86_64                                                                          6/9 
  Installing       : ghc-ghc-boot-th-devel-8.0.2-57.fc26.x86_64                                                                       7/9 
  Running scriptlet: ghc-ghc-boot-th-devel-8.0.2-57.fc26.x86_64                                                                       7/9 
  Installing       : ghc-template-haskell-devel-2.11.1.0-57.fc26.x86_64                                                               8/9 
  Running scriptlet: ghc-template-haskell-devel-2.11.1.0-57.fc26.x86_64                                                               8/9 
  Installing       : ghc-vector-th-unbox-devel-0.2.1.6-1.fc26.x86_64                                                                  9/9 
  Running scriptlet: ghc-vector-th-unbox-devel-0.2.1.6-1.fc26.x86_64                                                                  9/9 
  Verifying        : ghc-vector-th-unbox-0.2.1.6-1.fc26.x86_64                                                                        1/9 
  Verifying        : ghc-vector-th-unbox-devel-0.2.1.6-1.fc26.x86_64                                                                  2/9 
  Verifying        : ghc-primitive-0.6.1.0-3.fc26.x86_64                                                                              3/9 
  Verifying        : ghc-vector-0.11.0.0-3.fc26.x86_64                                                                                4/9 
  Verifying        : ghc-template-haskell-devel-2.11.1.0-57.fc26.x86_64                                                               5/9 
  Verifying        : ghc-vector-devel-0.11.0.0-3.fc26.x86_64                                                                          6/9 
  Verifying        : ghc-ghc-boot-th-devel-8.0.2-57.fc26.x86_64                                                                       7/9 
  Verifying        : ghc-primitive-devel-0.6.1.0-3.fc26.x86_64                                                                        8/9 
  Verifying        : ghc-transformers-devel-0.5.2.0-57.fc26.x86_64                                                                    9/9 

Installed:
  ghc-vector-th-unbox.x86_64 0.2.1.6-1.fc26                         ghc-vector-th-unbox-devel.x86_64 0.2.1.6-1.fc26                       
  ghc-ghc-boot-th-devel.x86_64 8.0.2-57.fc26                        ghc-primitive.x86_64 0.6.1.0-3.fc26                                   
  ghc-primitive-devel.x86_64 0.6.1.0-3.fc26                         ghc-template-haskell-devel.x86_64 2.11.1.0-57.fc26                    
  ghc-transformers-devel.x86_64 0.5.2.0-57.fc26                     ghc-vector.x86_64 0.11.0.0-3.fc26                                     
  ghc-vector-devel.x86_64 0.11.0.0-3.fc26                          

Complete!

[root@25721b8f2a36 math-functions]# cabal sandbox init
Config file path source is default config file.
Config file /root/.cabal/config not found.
Writing default configuration to /root/.cabal/config
Writing a default package environment file to
/tmp/math-functions/cabal.sandbox.config
Creating a new sandbox at /tmp/math-functions/.cabal-sandbox

[root@25721b8f2a36 math-functions]# cabal update
Downloading the latest package list from hackage.haskell.org

[root@25721b8f2a36 math-functions]# cabal install --dependencies-only
Resolving dependencies...
All the requested packages are already installed:
Use --reinstall if you want to reinstall anyway.

[root@25721b8f2a36 math-functions]# cabal build
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring math-functions-0.2.1.0...
Building math-functions-0.2.1.0...
Preprocessing library math-functions-0.2.1.0...
[ 1 of 10] Compiling Numeric.Sum      ( Numeric/Sum.hs, dist/build/Numeric/Sum.o )

Numeric/Sum.hs:59:1: warning: [-Wunused-imports]
    The import of `Data.Vector.Generic.Mutable' is redundant
      except perhaps to import instances from `Data.Vector.Generic.Mutable'
    To import instances alone, use: import Data.Vector.Generic.Mutable()
[ 2 of 10] Compiling Numeric.Polynomial.Chebyshev ( Numeric/Polynomial/Chebyshev.hs, dist/build/Numeric/Polynomial/Chebyshev.o )
[ 3 of 10] Compiling Numeric.Polynomial ( Numeric/Polynomial.hs, dist/build/Numeric/Polynomial.o )
[ 4 of 10] Compiling Numeric.MathFunctions.Constants ( Numeric/MathFunctions/Constants.hs, dist/build/Numeric/MathFunctions/Constants.o )
[ 5 of 10] Compiling Numeric.Series   ( Numeric/Series.hs, dist/build/Numeric/Series.o )
[ 6 of 10] Compiling Numeric.MathFunctions.Comparison ( Numeric/MathFunctions/Comparison.hs, dist/build/Numeric/MathFunctions/Comparison.o )
[ 7 of 10] Compiling Numeric.RootFinding ( Numeric/RootFinding.hs, dist/build/Numeric/RootFinding.o )
[ 8 of 10] Compiling Numeric.SpecFunctions.Internal ( Numeric/SpecFunctions/Internal.hs, dist/build/Numeric/SpecFunctions/Internal.o )

Numeric/SpecFunctions/Internal.hs:24:1: warning: [-Wunused-imports]
    The import of `expm1' from module `GHC.Float' is redundant
[ 9 of 10] Compiling Numeric.SpecFunctions ( Numeric/SpecFunctions.hs, dist/build/Numeric/SpecFunctions.o )
[10 of 10] Compiling Numeric.SpecFunctions.Extra ( Numeric/SpecFunctions/Extra.hs, dist/build/Numeric/SpecFunctions/Extra.o )

[root@25721b8f2a36 math-functions]# echo $?
0
Shimuuar commented 6 years ago

Downloading template-haskell-2.12.0.0... Installing : ghc-template-haskell-devel-2.11.1.0-57.fc26.x86_64

I suspect this is cause of problems. Using versions of template-haskell which is different from one that comes with GHC is not really supported and will cause all sorts of trouble.

atodorov commented 6 years ago

@Shimuuar I'm not sure I follow your comment above. ghc-template-haskell-devel 2.11.1 is coming from Fedora's RPMs and is older than what cabal downloads from Hackage. However with the older RPM compilation seems to work.

So are you telling me I need a newer compiler to be able to use template-haskell-2.12.0.0 ? This I don't quite understand.

Also from "Using versions of template-haskell which is different from one that comes with GHC": if the template-haskell module comes with GHC why then cabal downloads it again? Or maybe on Fedora that package doesn't come bundled with GHC by default. I'm not sure what's the default on Ubuntu.

Shimuuar commented 6 years ago

Yes. GHC 8.0.2 ships with template-haskell 2.11.1 and 2.12 somes with GHC 8.2. AFAIK using template haskell with wrong version of GHC is not supported since they're too tightly interwined,

Technically cabal can download and build template-haskell but it probably won't work. Usually it comes with GHC so cabal don't even try to build it. It looks like Fedora made weird decision to ship TH separately. It comes with GHC when installing from source and in Debian.

atodorov commented 6 years ago

@clumens ^^^ any ideas on how to resolve this on Fedora ?

Also if TH is so dependent on the GHC version I guess they should add some requirements for cabal (if at all possible) so that cabal will fail if the GHC version isn't right.

Shimuuar commented 6 years ago

Maybe adding manual constraint could help? cabal install --constraint=template-haskell-2.11.1

Shimuuar commented 6 years ago

Anyway I'm closing this issue since it's not a math-functions bug