sevo
sevo

Reputation: 4609

How can I import other Stack modules in ghci script?

I have a sequence of IO actions to run before I can explore data in GHCI. So I use this command:

stack ghci --ghci-options "-ghci-script Scratch.hs"

The problem is that other modules are not found and cannot be imported. They are compiled later though and subsequently can be imported interactively. How can I change this order?

Upvotes: 1

Views: 347

Answers (1)

epsilonhalbe
epsilonhalbe

Reputation: 15967

you could write a project specific .ghci file:

.ghci

import qualified Data.Text as T

:set prompt "Custom GHCi Script > "
:set -XOverloadedStrings

putStrLn "Hello Darkness my old Friend!"

then remove all write permissions for non owner

$ > chmod go-w .ghci

and finally

$ > stack ghci

or

$ > stack ghci --package text --load Scratch.hs
Configuring GHCi with the following packages:
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Hello Darkness my old Friend!
Loaded GHCi configuration from /home/epsilonhalbe/.ghci
Loaded GHCi configuration from /home/epsilonhalbe/.ghc/ghci.conf
Loaded GHCi configuration from /tmp/ghci24482/ghci-script
Custom GHCi Script > a = T.pack "Text"
Custom GHCi Script > :t a
a :: T.Text
Custom GHCi Script >

Upvotes: 1

Related Questions