0

I'm using Gentoo Linux and I have the network package installed:

$ equery l network
[IP-] [  ] dev-haskell/network-3.0.1.1:0/3.0.1.1
$ ls -la /usr/lib64/x86_64-linux-ghc-8.10.4/libHSnetwork-3.0.1.1-...-ghc8.10.4.so
-rwxr-xr-x 1 root root 705152 12. Nov 04:58 /usr/lib64/x86_64-linux-ghc-8.10.4/libHSnetwork-3.0.1.1-...-ghc8.10.4.so

There is no newer Gentoo package in the standard repository. But there are newer versions in Cabal. I even managed to install the newest one locally:

$ ls -la ~/.cabal/store/ghc-8.10.4/network-3.1.2.5-.../lib/libHSnetwork-3.1.2.5-...-ghc8.10.4.so
-rwxr-xr-x 1 jdoe jdoe 1610088 28. Nov 02:52 /home/jdoe/.cabal/store/ghc-8.10.4/network-3.1.2.5-.../lib/libHSnetwork-3.1.2.5-...-ghc8.10.4.so

I need this newst one to compile another package, but when I try to compile that, I still get the same error. Asking for the installed version yields:

$ cabal list --installed network
* network
    Synopsis: Low-level networking interface
    Default available version: 3.1.2.5
    Installed versions: 3.0.1.1
    Homepage: https://github.com/haskell/network
    License:  BSD3

What can I do to make Cabal aware that it has the newer version installed locally?

I try to compile Monky https://github.com/monky-hs/monky.git. First, the error message is

Monky/MPD.hs:222:10: error:
    Variable not in scope:
      unsafeFdSocket :: MPDSock -> IO Foreign.C.Types.CInt
    |
222 |   Fd <$> unsafeFdSocket s
    |          ^^^^^^^^^^^^^^

I found that unsafeFdSocket is defined since network-3.1.1, therefore I changed the lines around 222 to:

#if MIN_VERSION_network(3,1,1)
  Fd <$> unsafeFdSocket s
#else
  pure . Fd $ fdSocket s
#endif

Now the error message says:

Monky/MPD.hs:224:15: error:
    • Couldn't match expected type ‘Foreign.C.Types.CInt’
                  with actual type ‘IO Foreign.C.Types.CInt’
    • In the second argument of ‘($)’, namely ‘fdSocket s’
      In the expression: pure . Fd $ fdSocket s
      In an equation for ‘getMPDFd’:
          getMPDFd (MPDSocket s) = pure . Fd $ fdSocket s
    |
224 |   pure . Fd $ fdSocket s
    |               ^^^^^^^^^^
bertramscharpf
  • 175
  • 1
  • 10

1 Answers1

1

Your cabal file contains this line:

build-depends:       text, unix, network, mtl, transformers

You can add a version constraint like this:

build-depends:       text, unix, network >= 3.1.1, mtl, transformers
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • That helped. Thank you. However, I still do not know how cabal chooses which of the two paths `/usr/lib...` and `~/.cabal/...` to prefer. – bertramscharpf Nov 28 '21 at 21:13
  • @bertramscharpf Legacy cabal prefers user directories unless you explicitly specify `--global`. Modern cabal also offers a `--global`/`--user` distinction, but I'm less confident I understand how that affects its behavior; it may only affect the final location that build products are copied to during explicit installation commands. Explicit installation of libraries is much less common with modern cabal than it was with legacy cabal. If you can say more about why you care, it may be possible to say more about how to achieve your goals without knowing the answer. – Daniel Wagner Nov 28 '21 at 21:30