alex icon indicating copy to clipboard operation
alex copied to clipboard

Could not load module ‘Data.Array’

Open MartinErwig opened this issue 2 months ago • 4 comments

Loading a file generated with Alex (version 3.5.4.0) into ghci (version 9.6.7, which is the currently recommended version by ghcup), produces the following error message:

IdNum.hs:9:1: error:
    Could not load module ‘Data.Array’
    It is a member of the hidden package ‘array-0.5.8.0’.
    You can run ‘:set -package array’ 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.
  |
9 | import qualified Data.Array
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^

This can of course be fixed by the user as indicated in the error message, but it would be better if new users (e.g., students in a compilers class) would not have to be bothered with this.

Thanks, Martin

MartinErwig avatar Nov 01 '25 18:11 MartinErwig

How would you imagine this could be fixed on the side of alex?

andreasabel avatar Nov 02 '25 09:11 andreasabel

One could, for example, copy the necessary files and use them as part of the Alex distribution. Admittedly, this might not be an ideal solution. But one could at least provide some hint about this problem in the installation section of Alex. The point is that a user of Alex might not (want to) know anything about hidden packages. When after successfully installing Alex a user is confronted with this error message, they wonder whether there is anything wrong with their GHC installation.

MartinErwig avatar Nov 04 '25 22:11 MartinErwig

On my machine, I cannot reproduce your problem. However, I have experienced it before (but already quite a while ago), and it was related to GHC's package environments, which are documented here:

  • https://ghc.gitlab.haskell.org/ghc/doc/users_guide/packages.html#package-environments

In the default environment, the GHC-shipped packages such as array are declared as visible. As soon as you use .cabal files to describe your project, all packages are hidden by default and you need to declare all dependencies explicitly.

If you are experiencing the problem without having a .cabal file and no local environment file (look for .ghc.environment*), then maybe your default environment is broken.

Here is a similar problem described on stackoverflow:

  • https://stackoverflow.com/questions/79502535/hidden-packages-in-haskell-again-is-the-documentation-up-to-date

In essence, nothing of this is particular to alex.

If you isolate your problem and the solution to it, I am open to accept a Troubleshooting section to the alex user manual; this would be a new main chapter. Doc sources are here: https://github.com/haskell/alex/tree/master/doc and the rendering is at https://haskell-alex.readthedocs.io/en/latest/ .

andreasabel avatar Nov 06 '25 07:11 andreasabel

Thanks for the clarification and for the links to the discussion of the (somewhat involved) package handling rules.

-- Martin

On Nov 5, 2025, at 11:23 PM, Andreas Abel @.***> wrote:

[This email originated from outside of OSU. Use caution with links and attachments.] andreasabel left a comment (haskell/alex#281) On my machine, I cannot reproduce your problem. However, I have experienced it before (but already quite a while ago), and it was related to GHC's package environments, which are documented here: • https://ghc.gitlab.haskell.org/ghc/doc/users_guide/packages.html#package-environments In the default environment, the GHC-shipped packages such as array are declared as visible. As soon as you use .cabal files to describe your project, all packages are hidden by default and you need to declare all dependencies explicitly. If you are experiencing the problem without having a .cabal file and no local environment file (look for .ghc.environment*), then maybe your default environment is broken. Here is a similar problem described on stackoverflow: • https://stackoverflow.com/questions/79502535/hidden-packages-in-haskell-again-is-the-documentation-up-to-date In essence, nothing of this is particular to alex. If you isolate your problem and the solution to it, I am open to accept a Troubleshooting section to the alex user manual; this would be a new main chapter. Doc sources are here: https://github.com/haskell/alex/tree/master/doc and the rendering is at https://haskell-alex.readthedocs.io/en/latest/ . — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

MartinErwig avatar Nov 07 '25 01:11 MartinErwig

Closing this as "not specific to alex".

andreasabel avatar Dec 26 '25 14:12 andreasabel