Hidden package text and module not loading

This problem is known already for some time but is there any final solution?
I tried to build a program with cabal to use Colourista - no success.
Next I tried that with some success using stack, It seems to have corrupted some other packages or their modules. The business using :set -package text for example is no real solution for issue, not loading module Data.Text as it works only interactively with ghci, needing set procedure again, everytime just before manual loading :l .

I used the following code to test running Colourista.

module Main
where

import Colourista

import qualified Data.Text as Text

main = successMessage $ Text.pack "Hi, this is Colourista in Haskell all set up! However, the module Data.Text cannot be loaded from the hidden package text!"

At first it fails in loading the modules. Next, it continues succesfully after manual set.
At last, even Colourista will show correctly the text in color.

% ghci HiddenPackage.hs 
Loaded package environment from /Users/xyz/.ghc/aarch64-darwin-9.4.8/environments/default
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling Main   ( HiddenPackage.hs, interpreted )

HiddenPackage.hs:6:1: error:
    Could not load module ‘Data.Text’
    It is a member of the hidden package ‘text-2.0.2’.
    You can run ‘:set -package text’ 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.
  |
6 | import qualified Data.Text as Text
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
ghci> :set -package text
package flags have changed, resetting and loading new packages...
ghci> :l HiddenPackage.hs 
[1 of 2] Compiling Main  ( HiddenPackage.hs, interpreted )
Ok, one module loaded.
ghci> main
  ✔ Hi, this is Colourista in Haskell all set up! However, the module Data.Text cannot be loaded from the hidden package text!
ghci> 

The error of hidden package is back as soon as quitted from ghci.
Then you can’t even compile the programs with hidden packages because ghc will stop due to error.

This error is comparable to kind of coputer virus violating system function seriously.

Shall I clean/purge, reload and install Haskell completely to get rid of the hidden (corrupted?) packages or is there a quick solution.

It seems that you haven’t added the coulourista package to your build-depends in your .cabal file, or package.yaml.

May I suggest reading these guides?

Cabal getting started guide

https://cabal.readthedocs.io/en/stable/getting-started.html

Stack getting started guide

https://docs.haskellstack.org/en/stable/tutorial/

2 Likes

Also, don’t worry about the error too much. The tool just can’t find colourista by default because it isn’t declared in your project’s dependencies

1 Like

As @0rphee is suggesting, you should make a .cabal file for your project and add text and colourista as build-depends. Then use cabal build to build the project (replacement for direct ghc invocation) and cabal repl to run the REPL (replacement for direct ghci invocation).

1 Like

I have defined Colourista build dependencies. I have finally built with stack instead of cabal and added colourista also into extra-dependencies.
I think Colourista is ready to use because it can be iported without any error messages. I could also run the short example showing the green text using colourista. However Data.Text is not in order. I believed text is part of the basic Haskell but it seems not to be there.

I have this in my ~/.ghci for convenience in ghci:

:set prompt  "\x03BB: "
:set -XOverloadedStrings
:set -XDeriveGeneric
import Data.Text

Which seems to work:

$ ghci
GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/asjo/.ghci
λ: let hep = "yay" :: Text
λ: :t hep
hep :: Text

It’s not “part of the basic Haskell”, it’s a separate package. You need to add text to your build dependencies.

1 Like

In order to avoid confusion, one should refer to the pre-bundled packages as the “boot” packages, needed for a GHC installation. These are not a “Haskell distribution” like Haskell for Mac used to be. Please always rely on a cabal file for reproducibility.

If you really do not want to use Cabal, look at this page to see which libraries GHC comes packaged with: 2.1. Version 9.10.1 — Glasgow Haskell Compiler 9.10.1 User's Guide

2 Likes

As I’m still just beginner in Haskell, this was the first time I tried building a package. So I believe I have surely made one or more errors which may have caused some issues. For example, in the very beginning of the project, I made this:
cabal install Colourista
I read later I should have request: ```cabal -lib install
It didn’t allow reinstall it as it was there internal and only building was left as option.
As nothing was succeeded in cabal I wanted to uninstall my project but there is no uninstall instruction in cabal and deleting the workfiles did not remove Colourista. Finally I decided to kill the workfolder used in cabal and started build with stack where I can at least use stack clean and purge instructions.

I see, it’s mentioned also here in the cabal file.

 build-depends:       ansi-terminal >= 0.10    && < 1.2
                     , bytestring    >= 0.10    && < 0.13
                     , text          >= 1.2.3.0 && < 2.2 

How about ansi-terminal, is it also needed in the build-depends if I have not installed it yet?

This is the cabal file for the colourista package. Do you have a cabal file for your project? Creating one will let you add the text and colourista dependencies to that section you highlighted, for your package, that you will build and run with cabal build and cabal run, or use interactively with cabal repl. When you have a working version of your executable that you’d like to call by name in the terminal, you can run cabal install to use the binary with the name of your project. For example, the project my-terminal would need a my-terminal.cabal file and would install to the binary my-terminal.

I will then direct you to cabal’s own tutorial. :slight_smile:

1 Like

This version is slightly different:

:set prompt  "\x03BB: "
:set -package text
import Data.Text as Text
import Colourista
let alias = "Polarit"
successMessage $ Text.pack alias

It works with type String, for some reason not with type Text

Loaded package environment from /Users/xyz/.ghc/aarch64-darwin-9.4.8/environments/default
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
package flags have changed, resetting and loading new packages...
  ✔ Polarit
Loaded GHCi configuration from /Users/xyz/.ghci
λ: alias
"Polarit"
it :: String
λ:

There’s a really simple way to get started with this, but it’s hard to put into words, so I made an example repo. You can clone the repo at GitHub - tomjaguarpaw/colourista-and-text and then run the program (instead of using ghc directly) like this

$ cabal run
[...]
Building executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
[1 of 1] Compiling Main             ( Main.hs, /home/tom/Haskell/colourista-and-text/dist-newstyle/build/x86_64-linux/ghc-9.4.8/colourista-and-text-0.0.0.0/x/colourista-and-text/build/colourista-and-text/colourista-and-text-tmp/Main.o ) [Source file changed]
[2 of 2] Linking /home/tom/Haskell/colourista-and-text/dist-newstyle/build/x86_64-linux/ghc-9.4.8/colourista-and-text-0.0.0.0/x/colourista-and-text/build/colourista-and-text/colourista-and-text [Objects changed]
  ✔ Polarit

or use the REPL (instead of ghci) like this

$ cabal repl
[...]
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling Main             ( Main.hs, interpreted )
Ok, one module loaded.
ghci> example = "foo bar baz"
ghci> import Data.Text
ghci> import Colourista
ghci> successMessage (pack example)
  ✔ foo bar baz
3 Likes

Great, it works! Thanks!

MacBook-Pro colourista-and-text-master % cabal run
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - colourista-and-text-0.0.0.0 (exe:colourista-and-text) (first run)
Configuring executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
Preprocessing executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
Building executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
[1 of 1] Compiling Main             ( Main.hs, /Users/polarit/myhaskell/colourista-and-text-master/dist-newstyle/build/aarch64-osx/ghc-9.4.8/colourista-and-text-0.0.0.0/x/colourista-and-text/build/colourista-and-text/colourista-and-text-tmp/Main.o )
[2 of 2] Linking /Users/polarit/myhaskell/colourista-and-text-master/dist-newstyle/build/aarch64-osx/ghc-9.4.8/colourista-and-text-0.0.0.0/x/colourista-and-text/build/colourista-and-text/colourista-and-text
ld: warning: ignoring duplicate libraries: '-lm'
  ✔ Polarit
MacBook-Pro colourista-and-text-master % 

There is more, all the files as needed in building were created and saved!

-rw-r--r--@ 1 polarit  staff  574 14 Sep 20:02 colourista-and-text.cabal
-rw-r--r--@ 1 polarit  staff  133 14 Sep 20:02 Main.hs
-rw-r--r--@ 1 polarit  staff  984 15 Sep 00:31 README.md
drwxr-xr-x  6 polarit  staff  192 15 Sep 00:34 dist-newstyle

The same was run with cabal repl, cabal file and source copied to another folder.

torpl % cabal repl
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - colourista-and-text-0.0.0.0 (exe:colourista-and-text) (first run)
Configuring executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
Preprocessing executable 'colourista-and-text' for colourista-and-text-0.0.0.0..
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
package flags have changed, resetting and loading new packages...
  ✔ Polarit
Loaded GHCi configuration from /Users/polarit/.ghci
[1 of 2] Compiling Main             ( Main.hs, interpreted )
Ok, one module loaded.
λ: example = "made in REPL!"
λ: import Data.Text
λ: import Colourista
λ: successMessage (pack example)
  ✔ made in REPL!
λ: :q
Leaving GHCi.
1 Like

Thanks for considering the use of Stack. One way to do what you want to do, with Stack, is as follows:

  1. Command stack new my-project and cd my-project to set up a simple one-package template project (you can give it whatever valid package name you like). (Currently, that will pick Stackage LTS 22.34 as a ‘snapshot’: that is, a set of package versions known, by testing, to work well together.)

  2. You want your package to use modules exposed by the text and colourista packages, so you need to identify them as dependencies of your project package. Add those packages as dependencies to the package.yaml file specifying your project package (extract):

dependencies:
- base >= 4.7 && < 5
- colourista
- text

(Versions of both these packages are included in the LTS 22.34 snapshot.)

  1. Modify the app/Main.hs file for your simple example (updated):
module Main (main) where

import Colourista
import qualified Data.Text as Text

main :: IO ()
main = successMessage $
  Text.pack "Hi, this is Colourista in Haskell all set up!"
  1. Then, you can command stack ghci (or, equivalently, stack repl) to invoke GHC’s interactive mode pre-loaded with your project’s modules. At the GHCi prompt, command main and - bingo! - all works as you intended
ghci> main
  ✔ Hi, this is Colourista in Haskell all set up!
  1. EDIT: Outside of GHCi, command stack install (equivalent to stack build --copy-bins) to build your project and copy the executable file to a defined location (which you may have set to be on the PATH).
1 Like

As I found that cabal run works, I didn’t scare to try even cabal install.
Result: It works pretty well!
The saved command is available anywhere in darwin:

% cabal install
Wrote tarball sdist to
/Users/polarit/myhaskell/colourista-and-text-master/dist-newstyle/sdist/colourista-and-text-0.0.0.0.tar.gz
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - colourista-and-text-0.0.0.0 (exe:colourista-and-text) (requires build)
Starting     colourista-and-text-0.0.0.0 (exe:colourista-and-text)
Building     colourista-and-text-0.0.0.0 (exe:colourista-and-text)
Installing   colourista-and-text-0.0.0.0 (exe:colourista-and-text)
Completed    colourista-and-text-0.0.0.0 (exe:colourista-and-text)
Symlinking 'colourista-and-text' to
'/Users/polarit/.cabal/bin/colourista-and-text'
MacBook-Pro colourista-and-text-master % ~/.cabal/bin/colourista-and-text 
  ✔ Polarit

MacBook-Pro ~ % colourista-and-text
  ✔ Polarit
MacBook-Pro ~ %
1 Like

I cloned this and now it proposes to build again every time as I’ll use cabal REPL.
Can anybody please help me telling, how to restore cabal repl, set to the original unmodified state?

Can you give an example of what you mean? The command you are running, and the output?

Here is example


  1. HGCi works normally - with a little change, propt λ: which I defined.
    It begins this way

myhaskell % ghci
Loaded package environment from /Users/polarit/.ghc/aarch64-darwin-9.4.8/environments/default
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/xyz/.ghci
λ: 

exit this way


λ:  :q
Leaving GHCi.
myhaskell %
  1. This is the altered cabal REPL
myhaskell % cabal repl
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (lib) (first run)
Configuring library for fake-package-0..
Warning: No exposed modules
GHCi, version 9.4.8: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/xyz/.ghci
Loaded GHCi configuration from /var/folders/nn/nk195p6n2038d_1ml53718lm0000gp/T/cabal-repl.-28504/setcwd.ghci
λ:  :q
Leaving GHCi.
myhaskell % 

I don’t even understand, 1. why does it propose to build some fake package on cabal in the beginning and
2. why does it tell “Leaving GHCI.” although I was running cabal repl ! and
3. why cabal REPL is using the settings given to GHCi ( prompt λ: ? )