Search code examples
haskellcabalcabal-install

I am trying to run cabal build, and I get the following error


Build profile: -w ghc-9.0.1 -O1
In order, the following will be built (use -v for more details):
 - csound-expression-dynamic-0.3.8 (lib) (requires build)
 - csound-expression-typed-0.2.7 (lib) (requires build)
 - csound-expression-opcodes-0.0.5.1 (lib) (requires build)
 - csound-expression-5.3.4 (lib) (requires build)
 - csound-sampler-0.0.10.0 (lib) (requires build)
 - csound-catalog-0.7.4 (lib) (requires build)
 - solve-0.2.0.0 (exe:solve) (first run)
Starting     csound-expression-dynamic-0.3.8 (lib)
Building     csound-expression-dynamic-0.3.8 (lib)

Failed to build csound-expression-dynamic-0.3.8.
Build log (
C:\Users\Shiro\AppData\Roaming\cabal\logs\ghc-9.0.1\csound-expres_-0.3.8-3e9f98bb37e846ae1dd789bc6c80c4d50504a214.log
):
Preprocessing library for csound-expression-dynamic-0.3.8..
Building library for csound-expression-dynamic-0.3.8..
[ 1 of 15] Compiling Csound.Dynamic.Tfm.DeduceTypes ( src\Csound\Dynamic\Tfm\DeduceTypes.hs, dist\build\Csound\Dynamic\Tfm\DeduceTypes.o )
[ 2 of 15] Compiling Csound.Dynamic.Tfm.UnfoldMultiOuts ( src\Csound\Dynamic\Tfm\UnfoldMultiOuts.hs, dist\build\Csound\Dynamic\Tfm\UnfoldMultiOuts.o )
[ 3 of 15] Compiling Csound.Dynamic.Types.Exp ( src\Csound\Dynamic\Types\Exp.hs, dist\build\Csound\Dynamic\Types\Exp.o )

src\Csound\Dynamic\Types\Exp.hs:202:66: error:
    * No instance for (Data.Functor.Classes.Eq1 RatedExp)
        arising from a use of `=='
    * In the second argument of `(&&)', namely
        `(ratedExpExp re == EmptyExp)'
      In the expression:
        isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp)
      In an equation for `isEmptyExp':
          isEmptyExp e
            = isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp)
            where
                re = unFix e
    |
202 | isEmptyExp e = isNothing (ratedExpDepends re) && (ratedExpExp re == EmptyExp)
    |                                                                  ^^
cabal.exe: Failed to build csound-expression-dynamic-0.3.8 (which is required
by exe:solve from solve-0.2.0.0). See the build log above for details.

This my first time touching Haskell and Cabal. So, from what I understand, I need solve.exe, which needs csound-expression-dynamic-0.3.8, which needs something else. How do I get it to work?


Solution

  • The problem is that ratedExpExp re == EmptyExp was earlier in the file than $(deriveEq1 ''RatedExp) was. GHC 9.0.1's release notes say this:

    • Breaking change: Template Haskell splices now act as separation points between constraint solving passes. It is no longer possible to use an instance of a class before a splice and define that instance after a splice. For example, this code now reports a missing instance for C Bool:

      class C a where foo :: a
      bar :: Bool
      bar = foo
      $(return [])
      instance C Bool where foo = True
      

    That can be fixed by moving the isEmptyExp method to after the $(deriveEq1 ''RatedExp) splice. Once you do that, you'll run into another error about a duplicate instance. That can be fixed by by wrapping instance Hashable1 IM.IntMap inside of a #if !MIN_VERSION_hashable(1,3,4), after which it will compile fine on GHC 9.0.1. I opened https://github.com/spell-music/csound-expression-dynamic/pull/3 to make these changes upstream, but until they're accepted, you can make them manually to get it to build.

    UPDATE: My PR to fix this was merged and a new version was uploaded to Hackage. After doing a cabal update, building on GHC 9 should now succeed with no changes required to your project.