I'm using stack ghci to start my REPL, based on the answer I got for my question on how to import a module installed with stack. This works fine, but I get initially a warning message Note: No local targets specified, so a plain ghci will be started with no package hiding or package options., followed by a bunch of suggestions about package hiding and options. My guess is that this is because I have not used stack init to setup a project, since I am still in the "playing around and learning" state and don't want a project yet. I have not found an explanation about the meaning of 'no local targets', but the effect to start a plain ghci is exactly what I want at that point. Is there a way to suppress this message? I looked at stack --help, but could not find something suitable.
As the Note (not warning) suggests, a plain ghci is started, which is rather uncommon situation when working with stack.
~$ stack ghci
Note: No local targets specified, so a plain ghci will be started with no package hiding or package options.
You are using snapshot: lts-14.12
If you want to use package hiding and options, then you can try one of the following:
* If you want to start a different project configuration than /home/username/.stack/global-project/stack.yaml, then you can use stack init to create a new stack.yaml for the packages in the
current directory.
* If you want to use the project configuration at /home/username/.stack/global-project/stack.yaml, then you can add to its 'packages' field.
Configuring GHCi with the following packages:
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /tmp/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude>
This means though that all you need to do to get the same behavior without the Note is just start ghci manually in the context of global stack environment:
~$ stack exec -- ghci
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Prelude>
In case that you want to make sure some package is installed for "playing around and learning" in the ghci session you can supply them as --package arguments
~$ stack exec --package massiv -- ghci
atomic-primops> using precompiled package
cabal-doctest > using precompiled package
scheduler > using precompiled package
massiv > using precompiled package
Completed 4 action(s).
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.Massiv.Array
Prelude Data.Massiv.Array>
stack exec --ghci as in lehins's answer did not work for me, but stack exec ghci did.
Related
I have stack installed on my computer for haskell:
Developers-MacBook-Pro:~ developer$ stack ghci
Configuring GHCi with the following packages:
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /private/var/folders/2x/t_2cl03x2092dkzvc702d7lc0000gn/T/ghci2170/ghci-script
Prelude>
As you can see version is still 8.0.1. Then I upgraded the stack as follow:
Developers-MacBook-Pro:~ developer$ stack upgrade
Current Stack version: 1.3.2, available download version: 1.4.0
Newer version detected, downloading
Querying for archive location for platform: osx-x86_64-static
Querying for archive location for platform: osx-x86_64
Downloading from: https://github.com/commercialhaskell/stack/releases/download/v1.4.0/stack-1.4.0-osx-x86_64.tar.gz
Download complete, testing executable
Version 1.4.0, Git revision e714f1dd3fade19496d91bd6a017e435a96a6bcd (4640 commits) x86_64 hpack-0.17.0
New stack executable available at /Users/developer/.local/bin/stack
After I start stack ghci again and I've got still version 8.0.1, what am I doing wrong?
The image shows, that ghci version 8.0.2 has successfully installed:
The path is /Users/developer/.stack/programs/x86_64-osx/
Update
In the path /Users/developer/.stack/, there is a folder called global-project and I change the yaml as follow:
Now stack ghci run on version 8.0.2:
Developers-MBP:~ developer$ stack ghci
Configuring GHCi with the following packages:
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /private/var/folders/2x/t_2cl03x2092dkzvc702d7lc0000gn/T/ghci526/ghci-script
According to https://docs.haskellstack.org/en/stable/faq/#what-version-of-ghc-is-used-when-i-run-something-like-stack-ghci,
The version of GHC, as well as which packages can be installed, are specified by the resolver.
So, to change the version of GHC used when executing stack ghci outside stack projects, do:
Find an existing resolver in ~/.stack/build-plan, e.g. lts-10.4, or download a new resolver you need;
Execute stack config set resolver lts-10.4. Yes it updates ~/.stack/global-project/stack.yaml.
As thus, stack ghci outside stack projects will use GHC 8.2.2, which is the GHC version specified by resolver lts-10.4 (This relationship can be found at https://www.stackage.org/lts-10.4, or in file ~/.stack/build-plan/lts-10.4.yaml which says ghc-version: '8.2.2').
stack is a build tool that coordinates building projects with different versions of GHC and sets of dependencies. So you can upgrade stack independently of ghc.
I'm not quite sure what the expected behavior of stack ghci is when it's run outside of a project directory. Presumably you con configure the default version of ghc to use in that case in your ~/.stack/config.yaml. See: http://docs.haskellstack.org/en/stable/yaml_configuration/
You should also be able to do:
$ stack ghci --with-ghc ghc-7.10.3
But usually the version of ghc is determined by the stackage snapshot you've configured for your project, for instance if you have a stack.yaml with:
resolver: lts-3.3
...you will be using ghc-7.10.3
Is there a way to load a package(s) using Stack in GHCI and play around with it ?
So, that when the ghci is loaded, we can import the modules and see it's type signature, etc.
For the packages present in Stackage,
$ stack ghci --package unix-time
And this will give you a repl with the package unix-time loaded in it:
Run from outside a project, using implicit global project config
Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack.yaml
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
λ> import Data.UnixTime
λ> :t getUnixTime
getUnixTime :: IO UnixTime
For multiple packages:
$ stack ghci --package unix-time --package download
Run from outside a project, using implicit global project config
Using resolver: lts-6.14 from implicit global project's config file: /home/sibi/.stack/global-project/stack.yaml
tagsoup-0.13.10: using precompiled package
xml-1.3.14: using precompiled package
time-locale-compat-0.1.1.3: using precompiled package
feed-0.3.11.1: download
feed-0.3.11.1: configure
feed-0.3.11.1: build
feed-0.3.11.1: copy/register
download-0.3.2.4: download
download-0.3.2.4: configure
download-0.3.2.4: build
download-0.3.2.4: copy/register
Completed 5 action(s).
Configuring GHCi with the following packages:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
Ok, modules loaded: none.
λ> import Network.Download
λ>
I have just two files A.hs and B.hs in a directory dir (so no cabal or stack.yaml files). A imports B (with just import B). Running stack ghci and loading A then fails, complaining about the import. Is there a way to get this working? Running the system-wide ghci, everything works fine of course.
The reason I'm asking is that I've switched to intero for Emacs, which uses stack, and I'd like to be able to use intero for random small bits of code that I have lying around.
Versions: ghc 8.0.1, stack 1.1.2.
I am running stack version 1.1.2 x86_64 hpack-0.14.1
$ stack exec which ghc
Run from outside a project, using implicit global project config
Using resolver: lts-5.10 from implicit global project's config file: /home/wisut/.stack/global-project/stack.yaml
/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc
but when using stack ghci with GHC.Paths it is return the wrong path
$ stack ghci
Run from outside a project, using implicit global project config
Using resolver: lts-5.10 from implicit global project's config file: /home/wisut/.stack/global-project/stack.yaml
Error parsing targets: The specified targets matched no packages. Perhaps you need to run 'stack init'?
Warning: build failed, but optimistically launching GHCi anyway
Configuring GHCi with the following packages:
GHCi, version 7.10.3: http://www.haskell.org/ghc/ :? for help
Ok, modules loaded: none.
Prelude> GHC.Paths.ghc
"/usr/bin/ghc-7.10.3"
I am running Arch linux with ghc 8.0.1 therefor there is no ghc-7 avaliable outside stack
[wisut#earth ~]$ which ghc
/usr/bin/ghc
[wisut#earth ~]$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1
[wisut#earth ~]$ ls -al /usr/bin/ghc
lrwxrwxrwx 1 root root 9 May 24 18:28 /usr/bin/ghc -> ghc-8.0.1
Looking at GHC.Paths source, I have no idea where the value are from. Is it the ENV vars?
{-# LANGUAGE CPP #-}
module GHC.Paths (
ghc, ghc_pkg, libdir, docdir
) where
libdir, docdir, ghc, ghc_pkg :: FilePath
libdir = GHC_PATHS_LIBDIR
docdir = GHC_PATHS_DOCDIR
ghc = GHC_PATHS_GHC
ghc_pkg = GHC_PATHS_GHC_PKG
Running stack exec env didn't see anything.
$ stack exec env | grep -i ghc
Run from outside a project, using implicit global project config
GHC_PACKAGE_PATH=/home/wisut/.stack/global-project/.stack-work/installx86_64-linux/lts-5.10/7.10.3/pkgdb:/home/wisut/.stack/snapshots/x86_64-linux/lts-5.10/7.10.3/pkgdb:/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/lib/ghc-7.10.3/package.conf.d
PATH=/home/wisut/.stack/global-project/.stack-work/install/x86_64-linux/lts-5.10/7.10.3/bin:/home/wisut/.stack/snapshots/x86_64-linux/lts-5.10/7.10.3/bin:/home/wisut/.stack/programs/x86_64-linux/ghc-7.10.3/bin:/home/wisut/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
How can I fix the wrong value? How to to config stack to make GHC.Paths return the correct one?
UPD
I tried running stack with --no-system-ghc and it didn't make any difference.
I tried to remove my ~/.cabal and ~/.stack folders. I had to do stack setup, and after stack re-installed the compiler it doesn't give me that wrong path, but it doesn't give me any path, the output of that command is now empty.
I have nothing special in any of Setup.hs too.
You are almost right, the GHC_ variables are CPP definitions coming from custom Setup.hs:
let buildinfo = emptyBuildInfo{
cppOptions = ["-DGHC_PATHS_GHC_PKG=" ++ show c_ghc_pkg,
"-DGHC_PATHS_GHC=" ++ show c_ghc,
"-DGHC_PATHS_LIBDIR=" ++ show libdir,
"-DGHC_PATHS_DOCDIR=" ++ show docdir ]
}
About your problem with wrong path, try to run stack --no-system-ghc ghci. If it still shows "/usr/bin/ghc-7.10.3" for GHC paths, then I suspect that you had GHC there when you compiled ghc-paths for GHC-7.10.3, and as stack is quite good in not rebuilding stuff, the old version of ghc-paths is still there. I don't know a way to rebuild a package in a snapshot, other then whiping ~/.stack and starting over; which might be a good idea. if you changed you global GHC stuff.
There is a related issue: Stop using system-ghc silently.
I'm trying to use http://hackage.haskell.org/package/persistent-1.2.3.0, but after installing it through "cabal install persistent", ghc doesn't find its exposed-modules:
Prelude> import Database.Persist.Types
<no location info>:
Could not find module `Database.Persist.Types'
It is not a module in the current program, or in any known package.
And ghc-pkg works fine:
$ ghc-pkg find-module Database.Persist.Types
/var/lib/ghc/package.conf.d
/home/apsk/.ghc/x86_64-linux-7.6.3/package.conf.d
persistent-1.2.3.0
Am I missing something or is this just a bug with cabal/persistent/ghc? My ghc is 7.6.3, btw.
Also, I've tried with no effect: "ghc-pkg recache"; "ghc-pkg check"; installing previous version; reinstalling with and without "sudo" and/or "--global".
Check that you're not using sandboxes, cabal-dev, hsenv, anything else that can influence ghc in looking for dependencies. Make sure you're using ghc/ghci, and not any wrappers, and that ghc/ghci are not aliased to anything in your shell.
Try to specify the package-db explicitly:
ghci -package-db /home/apsk/.ghc/x86_64-linux-7.6.3/package.conf.d
If you launch ghci with -v, it'll print the (caches of) databases it looks at, like this:
% ghci -v
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.4.2
Using binary package database: /opt/ghc763/lib/ghc-7.6.3/package.conf.d/package.cache
Using binary package database: /home/feuerbach/.ghc/i386-linux-7.6.3/package.conf.d/package.cache
Make sure that the database which has persistent is listed there.
Hopefully helpful to someone. Using ghci -v I looked to see if persistent was there, and saw this:
package persistent-2.0.8-cec952b1a61645f47dbec3b0b0cbcef4 is unusable due to missing or recursive dependencies: aeson-0.8.0.0-1bd8b5254a1dd30c0fe6acc346ad7de7 attoparsec-0.12.1.2-48393fcdbcf426085b696dc4409d9270 conduit-1.2.0.2-39f9cd0430ed7b7f4306899cbeb1ed83 monad-logger-0.3.7.2-3e6a80e9b3adf31497ff04514bdf2919 resource-pool-0.2.3.0-c02186641e7173f72887d5e65a646ac1 scientific-0.3.3.1-13e0eefbd7215e4503420c3d0a6fdb82 unordered-containers-0.2.5.0-147c3bb8f4a2da7d753455e75af30b92
So I looked around on SO (saw this: Haskell Cabal: Mysterious missing or recursive dependencies) but didn't find a great answer. I did find a good one here though:
$ ghc-pkg list Cabal
Which revealed I had 2 goddamn cabals! One in user and one in global. Ugh. So I was able to do ghc-pkg unregister --user Cabal-1.18.1.3 --force to get rid of the old one. Then cabal install cabal automatically went for 1.20, implicitly into user without any flag (the alternate would be --global).
The problem only occurs in GHCi, right? Have you restarted GHCi since installing persistent? (Maybe there's another way to get GHCi to pick up newly installed packages, but I'm not aware of it.