Should stack repl load test modules from *other* packages? - haskell

I have a project which pulls in two local packages. My stack.yaml has:
packages:
- '.'
- '../creatur-wains'
- '../creatur-wains-test-utils'
Both creatur-wains and creatur-wains-test-utils define a module called ALife.Creatur.Wain.TestUtils, but in creatur-wains it's only part of the test code, not part of the library. This wasn't a problem when I was using ghci. I could load both packages, and only the version of TestUtils from creatur-wains-test-utils was visible.
However, Stack also seems to pull in the test modules from creatur-wains, so I get the following error:
$ stack repl
The following GHC options are incompatible with GHCi and have not been passed to it: -Werror -threaded
Configuring GHCi with the following packages: creatur-dvector-wains, creatur-wains-test-utils, creatur-wains
* * * * * * * *
The following modules are present in multiple packages:
* ALife.Creatur.Wain.TestUtils (in creatur-wains, creatur-wains-test-utils)
* * * * * * * *
Not attempting to start ghci due to these duplicate modules.
Use --no-load to try to start it anyway, without loading any modules (but these are still likely to cause errors)
I can work around this using --no-load, and adding the packages one by one, but that's a bit tedious. Is this desireable behaviour for stack repl, or is it a bug?

From the stack ghci docs (https://docs.haskellstack.org/en/stable/ghci/):
Similarly to stack build, the default is to load up ghci with all libraries and executables in the project.
So, to load just one package you need to do stack ghci creatur-wains.

Related

ghci: module ‘main:Main’ is defined in multiple files - in new small stack init build ghci package

I try to setup a stack based Haskell IDE with vscode and start with a small project created with stack init and then added a second module in src and added some dependencies in package.yaml. It builds ok but when I start stack ghci I have warnings:
Warning: Multiple files use the same module name:
* Paths_primo found at the following paths
* /home/frank/Workspace11/primo/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/autogen/Paths_primo.hs (primo:lib)
* /home/frank/Workspace11/primo/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/primo-exe/autogen/Paths_primo.hs (primo:exe:primo-exe)
* * * * * * * *
GHCi, version 8.10.4: https://www.haskell.org/ghc/ :? for help
[1 of 3] Compiling Lib ( /home/frank/Workspace11/primo/src/Lib.hs, interpreted )
[2 of 3] Compiling YamlRead ( /home/frank/Workspace11/primo/src/YamlRead.hs, interpreted )
[3 of 3] Compiling Main ( /home/frank/Workspace11/primo/app/Main.hs, interpreted )
Ok, three modules loaded.
There seems to be a confusion with autogen and with Paths_primo (primo is the name of the package). What am I doing wrong?
General question: what is the correct way to clean a stack project to "start over" after some experimentation? Is is correct to delete the cabal file and the stack-work directory. Waht is with stack.yaml and 'stack.yaml.lock`?
This appears to be a harmless warning reported at Stack issue #5439, whose underlying cause is hpack issue #303. A workaround to get rid of the warning is disabling the generation of the Paths_ module for your primo-exe executable, by adding the following to its section in package.yaml:
when:
- condition: false
other-modules: Paths_primo

How to use custom prelude with stack ghci?

I added a custom Prelude, which is working well for stack build and stack test. However, stack ghci does not like it, as it seems to be trying to load all of these at once:
$ stack --nix ghci
XXX-0.1.0.0: initial-build-steps (lib + exe)
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: XXX
* * * * * * * *
Error: Multiple files use the same module name:
* Prelude found at the following paths
* XXX/server/Prelude.hs (XXX:exe:XXX.exe)
* XXX/src/Prelude.hs (XXX:lib)
* XXX/tests/Prelude.hs (XXX:exe:tests.exe)
* * * * * * * *
Not attempting to start ghci due to these duplicate modules.
First, to explain the three different Prelude.hs files: they are identical as two of them are symbolic links to the third file; I hadn't thought of a better way to do this without possibly exposing my Prelude.hs to dependent libraries.
A possible workaround would be to tell stack/ghci to only load the library code (under src in this case), or better yet, be able to tell it to skip particular .hs files on loading.

Stack fails to install intero

I just installed Stack using
curl -sSL https://get.haskellstack.org/ | sh
The install went fine but when trying to install Intero using Stack it fails
ffriis#BNEC02QR6Y0G8WN ~> stack install hlint intero
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for intero-0.1.32:
ghc-8.4.4 from stack configuration does not match >=7.8 && <=8.4.3 (latest matching version is 8.4.3)
needed since intero is a build target.
Some different approaches to resolving this:
* Set 'allow-newer: true' in /Users/ffriis/.stack/config.yaml to ignore all version constraints and build anyway.
* Consider trying 'stack solver', which uses the cabal-install solver to attempt to find some working build configuration. This can be convenient when dealing with many complicated constraint
errors, but results may be unpredictable.
* Recommended action: try adding the following to your extra-deps in /Users/ffriis/.stack/global-project/stack.yaml:
ghc-8.4.3#sha256:07ee8fb5dab414c35f93d5d5afc1ecaa65a49c409346e5063436cc8b838cd754
Plan construction failed.
I've edited the file as instructed but I'm still getting the same error. What is the best way to resolve the problem?
Currently intero supports GHC 8.4.3, but stack is grabbing 8.4.4. Change your resolver to lts-12.14 in stack.yaml

Stack is unable to resolve the correct package version

I am trying to use grenade in Haskell. Using stack as a configuration tool, I have
# stack.yaml
extra-deps:
- diagrams-solve-0.1.1
- dual-tree-0.2.2
- SVGFonts-1.6.0.3
- diagrams-core-1.4.1
- diagrams-lib-1.4.2.2
- diagrams-postscript-1.4.1
- diagrams-svg-1.4.2
- Chart-diagrams-1.8.3
- hip-1.5.3.0
- singletons-2.2
- template-haskell-2.11.1.0
- th-desugar-1.6
- grenade-0.1.0
But when I execute stack build, it gives me the following error
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for th-desugar-1.6:
template-haskell-2.12.0.0 from stack configuration does not match <2.12 (latest
matching version is 2.11.1.0)
needed due to Brain-0.1.0.0 -> th-desugar-1.6
Some different approaches to resolving this:
* Set 'allow-newer: true' to ignore all version constraints and build anyway.
* Consider trying 'stack solver', which uses the cabal-install solver to attempt to
find some working build configuration. This can be convenient when dealing with
many complicated constraint errors, but results may be unpredictable.
* Recommended action: try adding the following to your extra-deps
in [Project directory]/stack.yaml:
- template-haskell-2.11.1.0
Plan construction failed.
Even if I put - template-haskell-2.11.1.0 before diagrams-solve, stack still gives me the same error. Allowing newer versions is not viable since it breaks th-desugar.
That looks like a lot of extra-deps. I'd recommend figuring out a good resolver first. The best way to do that is use the original repo:
git clone git#github.com:HuwCampbell/grenade.git
cd grenade
stack init
Which gives you the following output:
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- ./
- examples/
Selecting the best among 13 snapshots...
* Partially matches lts-11.13
criterion version 1.3.0.0 found
- grenade requires ==1.1.*
Downloaded nightly-2018-06-16 build plan.
* Partially matches nightly-2018-06-16
criterion version 1.4.1.0 found
- grenade requires ==1.1.*
hmatrix version 0.19.0.0 found
- grenade requires ==0.18.*
- grenade-examples requires ==0.18.*
singletons version 2.4.1 found
- grenade requires >=2.1 && <2.4
* Partially matches lts-10.10
criterion version 1.2.6.0 found
- grenade requires ==1.1.*
Downloaded lts-9.21 build plan.
* Matches lts-9.21
Selected resolver: lts-9.21
Initialising configuration using resolver: lts-9.21
Total number of user packages considered: 2
Writing configuration to file: stack.yaml
All done.
So use the base resolver lts-9.21. And I'd open an issue on the repo of grenade to add it to stack.

Yesod build error because of the duplicate definition for symbol "hsprimitive_memcpy"

I followed "Yesod quick start guide" to install Yesod in Windows 10.
But, when I issued the stack build command, it failed.
Environment
Windows 10 (64bits)
stack-0.1.5 (for Windows10 64bits)
Haskell Platform 7.10.2-a (from HaskellPlatform-7.10.2-a-x86_64-setup.exe)
alex-3.1.4.log
GHC runtime linker: fatal error: I found a duplicate definition for symbol
hsprimitive_memcpy
whilst processing object file
C:\Users\xxxxx\AppData\Roaming\stack\snapshots\x86_64-windows\lts-3.8\7.10.2\lib\x86_64-windows-ghc-7.10.2\primitive-0.6.1.0-5Jnw7oEuYtM9dmKXelGXVb\HSprimitive-0.6.1.0-5Jnw7oEuYtM9dmKXelGXVb.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.2 for x86_64-unknown-mingw32):
loadObj "C:\\Users\\xxxxx\\AppData\\Roaming\\stack\\snapshots\\x86_64-windows\\lts-3.8\\7.10.2\\lib\\x86_64-windows-ghc-7.10.2\\primitive-0.6.1.0-5Jnw7oEuYtM9dmKXelGXVb\\HSprimitive-0.6.1.0-5Jnw7oEuYtM9dmKXelGXVb.o": failed
It seems that the cause of the error were the duplicated GHC installation.
Thanks for #Reid comment, I realized that I installed Haskel Platform from exe file before and I also installed GHC through stack by folloing the guide.
I unisatlled GHC of Haskel Platform and executed 'stack setup' command.
Then, I executed 'stack build' command and it seemed worked.
I still have problems with the 'stack build' command, but I solved this issue.

Resources