So, this is the nub of the paradox on Linux with runghc from GHC 9.4.8:
$ stack --snapshot lts-21.25 exec -- /home/mpilgrem/.stack/programs/x86_64-linux/ghc-tinfo6-9.4.8/bin/ghc-pkg list pandoc --simple-output
pandoc-3.0.1
$ stack --snapshot lts-21.25 exec -- /home/mpilgrem/.stack/programs/x86_64-linux/ghc-tinfo6-9.4.8/bin/runghc-9.4.8 -hide-all-packages -package=base -package=pandoc /home/mpilgrem/code/has
kell/script-test/example1.hs
/home/mpilgrem/code/haskell/script-test/example1.hs:8:1: error:
Could not load module ‘Text.Pandoc’
It is a member of the hidden package ‘pandoc-3.0.1’.
You can run ‘:set -package pandoc’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
8 | import Text.Pandoc
| ^^^^^^^^^^^^^^^^^^
I have raised: #25035: `-package=pandoc` ignored · Issues · Glasgow Haskell Compiler / GHC · GitLab
EDIT2: The reason I have raised this as a GHC issue is becuase I understand (a) -package=pandoc passed to runghc means ‘pass this same option on to GHC’ and (b) -package=pandoc passed to GHC means ‘cause the identified package to be exposed’. So, it should not be open to runghc to warn that pandoc-3.0.1 is hidden if it has been passed -package=pandoc.
EDIT: I am continuing to experiment with this, and getting some really odd outcomes. I am going to explore if older versions of Stack behave the same way.
EDIT3: I can reduce the nub further, having looked at the source code for runghc. On Ubuntu (via WSL2), with example.hs:
import Text.Pandoc
main :: IO ()
main = print pandocVersion
$ # GHC 9.4.8 ... does not work ...
$ stack --snapshot lts-21.25 exec -- ghc -hide-all-packages -package=base -package=pandoc example.hs
example.hs:1:1: error:
Could not load module ‘Text.Pandoc’
It is a member of the hidden package ‘pandoc-3.0.1’.
You can run ‘:set -package pandoc’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
1 | import Text.Pandoc
| ^^^^^^^^^^^^^^^^^^
$ # GHC 9.4.7 ... does work ...
$ stack --snapshot lts-21.21 exec -- ghc -hide-all-packages -package=base -package=pandoc example.hs
[1 of 2] Compiling Main ( example.hs, example.o )
[2 of 2] Linking example
(To confirm, it is something to do with -package=pandoc not exposing pandoc-3.0.1, because:
$ stack --snapshot lts-21.25 exec -- ghc example.hs
$ stack --snapshot lts-21.21 exec -- ghc example.hs
are both fine.)
EDIT: Resolution
The cause of this has been identified. It is, essentially, a bug in GHC, as follows:
GHC has the concept of installed packages in package databases, and an installed package has a name. The names of installed packages in package databases are provided by command ghc-pkg list.
For the Cabal package pandoc, the name of the installed package corresponding to the main (unnamed) library is pandoc. The name of the installed package corresponding to the internal library xml-light is z-pandoc-z-xml-light. Those names are what the tool ghc-pkg uses and reports.
However, the installed package corresponding to a named sub-library of a Cabal package also has a package-name, which corresponds to the name of the Cabal package. For installed package z-pandoc-z-xml-light it is pandoc.
Undocumented, GHC’s -package option treats package-name (if it exists) as if it were also the name of the installed package. That inconsistency with ghc-pkg means that GHC option -package=pandoc can’t distinguish between (a) the installed package pandoc and (b) the installed package z-pandoc-z-xml-light - so GHC picks one installed package ‘at random’ (that is, what GHC actually does is indeterminate).
What the original poster was experiencing is GHC picking internal package z-pandoc-z-xml-light to expose when passed -package=pandoc, and continuing to treat internal package pandoc as hidden.