Hidden package text and module not loading

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 λ: ? )

If you do cabal repl -b aeson -b servant then cabal brings the aeson and servant packages into scope by creating a “fake package” that depends on them both. I guess you do cabal rep with no -b then it still creates a fake package, that depends on nothing.

Because cabal repl is a wrapper around ghci.

Presumably because of this line

Loaded GHCi configuration from /Users/xyz/.ghci

Did you configure prompt λ: in that file? Because cabal repl is ghci it just picks up the normal configuration of ghci.

1 Like

Yes, I added that prompt by myself and there was nothing mystic yet cauz I could also cancel the setting otherwise as the git I downloaded and run.
I don’t know what aeson and servant do to my GHC, thus I’ll just stepwise kill all the suspective files created after downloading of the git snippet, listing first also the unvisible files with (unix/linux/mac) command lst -lrta. Maybe I’ll next destroy all of my GHC and upgrade ghcup, ghc, hls, stack and cabal with hope I’ll get rid of all garbage. I have still GHC version 9.4.8 as recommended by GHCup tui version 0.1.30.0.
Well, before doing all that, I’ll do virus scanning of the GHC beginning from the root ~/.ghcup/bin/

How about using the latest GHC 9.10.1, is it stable version? Is the recommended 9.4.8 kind of LTS version and the first selection for production, industrial, commercial, science or which ever use?

Currently, the GHC developers classify all of GHC 9.6.6, 9.8.2 and 9.10.1 as (EDIT) ‘current stable releases’: see Download — The Glasgow Haskell Compiler.

I am not in ‘industry’ but I understand that what ‘industry’ uses is path dependent for each user and, consequently, varies from user to user. That is because moving from one version of GHC to another brings costs (of the change) as well as benefits. I have seen some industry users say that when they move, they can ‘jump over’ some major versions.

The GHCup project weighs up various things when thinking about what GHC version to recommend. For example, see the discussion here: [RFC][GHCup] Should GHC 9.6.4 be 'recommended'?.

At Stackage, currently the most recent LTS uses GHC 9.6.6 and nightly uses GHC 9.8.2: see https://www.stackage.org/. That project tends to avoid the first minor version (sometimes, versions) of a new major version of GHC. I think it waits for users on the ‘cutting edge’ to reveal any bugs from use that are then fixed in later minor versions. A key FAQ is “Why is Stackage LTS still on an older version of GHC?” - see GitHub - commercialhaskell/stackage: Stable Haskell package sets: vetted consistent packages from Hackage.

3 Likes