Search code examples
haskellghccabalparsec

How to use Text.Parsec in GHC-8.2.2 and Cabal-2.0.0.1


As I know Text.ParserCombinators.Parsec is replaced by Text.Parsec

Here, it is my environment

4.9.73-1-MANJARO

The Glorious Glasgow Haskell Compilation System, version 8.2.2

cabal-install version 2.0.0.1
compiled using version 2.0.1.0 of the Cabal library 

The following source code is my main.hs

module Main where
import System.Environment
import Text.Parsec

main :: IO ()
main = do
     args <- getArgs
     putStrLn (readExpr (args !! 0))

and then I compile it

$ ghc -package parsec -o main main.hs

It occurs the following error messages

[1 of 1] Compiling Main             ( main.hs, main.o )

main.hs:3:1: error:
    Could not find module ‘Text.Parsec’
    There are files missing in the ‘parsec-3.1.11’ package,
    try running 'ghc-pkg check'.
    Use -v to see a list of the files searched for.
  |
3 | import Text.Parsec
  | ^^^^^^^^^^^^^^^^^^
rm: cannot remove '*.hi': No such file or directory
./run.sh: line 11: ./TestProj: No such file or directory

I make sure I have installed parsec. So I want to ask any mistake I've done?

$ cabal install parsec
Resolving dependencies...
All the requested packages are already installed:
parsec-3.1.11
Use --reinstall if you want to reinstall anyway.

Solution

  • Manjaro might have inherited from Arch's issues with Haskell.

    What is going on

    Arch installs dynamic libraries, but ghc links statically by default. This is also what the error message "There are files missing in the ... package", indicating that the package exists but does not contain what ghc is looking for.

    If I try compiling with the -v verbose flag on, the error message expands to:

    ghc -v main.hs
    
    (...)
    Locations searched:
      Text/Parsec.hs
      Text/Parsec.lhs
      Text/Parsec.hsig
      Text/Parsec.lhsig
      /usr/lib/ghc-8.2.2/site-local/parsec-3.1.11/Text/Parsec.hi
    (...)
    

    In particular, look into the last reported location, which may be different on your system; if my guess is correct, ghc is looking for a static interface file .hi as the message indicates but there is only a dynamic one .dyn_hi.

    Fix

    Compile with the -dynamic flag.

     ghc -dynamic main.hs
    

    And if that works read this to fix the setup:

    https://wiki.archlinux.org/index.php/Haskell

    You will have to choose between static and dynamic linking; I don't actually understand the trade-off here.