Encountering error while adding MaybeT dependency in stack project - haskell

I am following this tutorial webScraper using HXT.
I am using Stack here.
While adding dependency for MaybeT, it asked to:
Recommended action: try adding the following to your extra-deps in /Users/***/Haskell Development/Scraper/stack.yaml:
MaybeT-0.1.2
Now doing so to ended up with this message on running stack build:
In the dependencies for MaybeT-0.1.2:
base-4.9.0.0 must match <4.8 (latest applicable is 4.7.0.2)
needed due to Scraper-0.1.0.0 -> MaybeT-0.1.2
Being new to Stack, I am unable to solve the problem, in my cabal file the
the dependency:
build-depends: base >= 4.7 && < 5
, hxt
, url
, HTTP
, MaybeT
In stack.yaml
resolver: lts-7.12
extra-deps: [MaybeT-0.1.2]
What is it that I have missed. How can I solve this?

The solution for your concrete problem is switching from the outdated MaybeT package to the MaybeT transformer offered by the transformers package in Control.Monad.Trans.Maybe.
That said, note that the version mismatch involves base. If you actually needed to use the MaybeT package, you would have to switch the Stack resolver to a snapshot such as lts-6.26, which uses base-4.8 or below (i.e. GHC 7.10.3 or below). base versions are coupled to GHC versions, and everything else depends on base, so there is no easy way of switching just base to an older version, as it might be possible, given some luck, with other packages.

Related

Building the Spock tutorial example fails

I wanted to get going with Haskell a little bit and therefore took a look at the Spock framework. To start clean, I uninstalled everything Haskell related from my Arch Linux machine and installed ghcup, Cabal and Stack using the install scripts from their respective websites.
Now I want to follow Spock's Tutorial. Trying to install Spock globally with cabal install Spock as suggested gives me an error (abbreviated):
src/Web/Spock/Internal/Wire.hs:43:1: error:
Could not find module ‘Web.Routing.AbstractRouter’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
43 | import Web.Routing.AbstractRouter
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build Spock-0.9.0.1. See the build log above for details.
I already found a question on reddit on the topic, but the solution does not apply because I'm not trying to use a specific version of the libraries as implied.
So I try to follow along and build only locally.
But when I reach the point where it says stack build --fast --pedantic, the build plan can not be constructed and Stack suggests to add another dependency, stm-containers. Doing so, I am presented with two additional suggestions for focus and primitive. When I add these, the plan fails again, this time without a simple solution:
In the dependencies for primitive-0.6.4.0:
base-4.13.0.0 from stack configuration does not match >=4.5 && <4.13 (latest matching version is 4.12.0.0)
needed due to Spock-example-0.1.0.0 -> primitive-0.6.4.0
I can do a little thing with Haskell, but with the build system(s), I am way out of my comfort zone. Help and hints appreciated. Oh, and all versions of course are the latest by the time of this post.
Due to incompatible versions of dependencies, Spock won't build with GHC 8.8 and above. A similar problem is described in Spock issue #149, though I'm not fully sure it is exactly the same incompatibility. The error you got from Stack hints at that, as base-4.13.0.0 is the version of base that is bundled with GHC 8.8. cabal-install failed in a more obscure way because, upon noting the incompatibility, it tries to solve the dependencies using older versions of Spock, eventually picking 0.9.0.1, attempting and, thanks to a missing version upper bound for the reroute dependency, failing to build it.
(Shortly after this answer was posted, the missing upper bound was retrofitted to the old Spock version, so attempting to reproduce the problem now will lead to an easier to understand failure.)
Casting the tutorial aside, the most straightforward way to use Spock given those complications is probably through cabal-install 3+. Begin by using ghcup to switch to GHC 8.6.5:
$ ghcup install 8.6.5
$ ghcup set 8.6.5
Then, create a blank project with cabal-install:
$ mkdir myproject
$ cd myproject
$ cabal init
Add Spock to the build-depends section of myproject.cabal:
build-depends: base >=4.12 && <4.13
, Spock == 0.13.*
Finally, you can run:
$ cabal build
Which will install Spock and its dependencies before building the project. (Note that you generally don't need to use cabal install to install libraries with cabal-install 3.)
It is presumably possible to make it work with Stack as well, by changing to the lts-14.27 resolver (the latest one that uses GHC 8.6.5), tracking down all dependency versions that need to be overriden (as you had began to do) and manually adding them to the extra-deps of stack.yaml.

How does stack resolve dependencies? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How does stack resolve dependecy conflicts?
I just started off with Haskell and I have few questions on how stack resolves dependencies.
Let's say my project requires lib A and lib B.
Internally, lib A requires lib X-1.9.0 and lib B requires lib X-2.0.0, how would stack resolve this?
stack documentation says they use snapshots to resolve conflicts, how does that work? Does it mean authors of lib A and lib B decide on a version of lib X which works with both of them? If so, what happens when I use a newer version of lib A or lib B or if either of them are not in the snapshots?
How are snapshots actually made?
Stack by default installs packages globally. What happens when a Project A requires lib Y-1.0 and Project B requries lib Y-1.1? How does this gets taken care of?
How does one use packages at "stackage.org"?
I was trying to install beam-core and google took me to https://www.stackage.org/package/beam-core where there's no mention of the command which installs it or what is the latest version. I could not find the version number anywhere expect in github releases.
With both pip and npm, it's quite straight forward and all the information on how to install and use is available on package's page. For example both,
https://pypi.org/project/bencode.py/
https://www.npmjs.com/package/projects
contains version number and install command, even though they are quite obvious.
I often get errors related to 'stack-configuration' when I try to install a package. I don't what 'stack-configuration' is?
What does all these errors mean and how to resolve them in context with all the above questions?
Performing stack install beam-core or stack repl --package beam-core --package beam-sqlite --package sqlite-simple --package beam-migrate --package text results in
`Users/username/Documents/beam-learn/beam-learn.cabal was modified manually. Ignoring /Users/username/Documents/beam-learn/package.yaml in favor of the cabal file.
If you want to use the package.yaml file instead of the cabal file,
then please delete the cabal file.
Stack has not been tested with GHC versions above 8.6, and using 8.8.2, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for hashable-1.2.7.0:
base-4.13.0.0 from stack configuration does not match >=4.4 && <4.13 (latest matching version is 4.12.0.0)
needed due to beam-core-0.8.1.0 -> hashable-1.2.7.0
Some different approaches to resolving this:
* Set 'allow-newer: true' in /Users/username/.stack/config.yaml to ignore all version constraints and build anyway.
* Build requires unattainable version of base. Since base is a part of GHC, you most likely need to use a different GHC version with the matching base.
Plan construction failed.`
For question #1:
Stack is designed around the concept that, for a given Stack project, only one version of a given package will be used. So, if you have a project that requires libraries A and B, and each of them depend on different versions of library X, then you cannot build your project as-is with Stack.
Snapshots are constructed by building collections of versions of packages (with exactly one version per package) such that all inter-package dependencies can be satisfied. This is done by the Stackage "curators" as described here using the curator tool. The curator tool uses the index of packages available on Hackage to construct a set of versions of packages (exactly one version per package) that are compatible in the sense that all package interdependencies are satisfied.
So, the library authors don't need to decide on a version of X that works with both. Rather, they need to specify a range of versions of X that their package works with, and the curator tool selects the most recent version of X that works with both their packages, as well as everyone else's packages that depend on X or on which X has a dependency.
If you want to use a newer version of library A or B that isn't in the snapshot, you add it as an extra dependency in your build plan (i.e., in the extra-deps section of your stack.yaml file). If the new version can't be built with the snapshot's version of X, you need to add an extra dependency for X too. If that breaks other packages and you can't find a set of extra dependencies that resolves all conflicts, you're out of luck.
In practice, because most packages have relatively generous ranges of dependencies and, for actively maintained packages, those ranges are generally kept up to date with newer compatible dependency versions, you don't often run into unresolvable conflicts, but it does happen.
For question #2:
Stack doesn't really install packages globally. It installs snapshot packages in a global cache (on Linux, in the directory ~/.stack) organized by snapshot. So, multiple versions can be installed in this cache under different snapshots, and the project will use whichever version is appropriate for the project's selected snapshot.
For question #3:
On the Stackage page for beam-core, you can see that the most recent LTS snapshot that contains it is lts-14.27. You can create a new project using this resolver with:
$ stack new --resolver lts-14.27 my-beam-project
To add beam-core to your project, edit my-beam-project/package.yaml and add a dependency:
dependencies:
- base >= 4.7 && < 5
- beam-core # <-- add this
Now, run stack build in your my-beam-project directory:
$ cd my-beam-project
$ stack build
It will build beam-core and all its dependencies which takes a few minutes, unless you've built beam-core for this snapshot before.
You can fiddle around with beam-core by running stack ghci in your project:
$ stack ghci
...
Configuring GHCi with the following packages: my-beam-project
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Lib ( /u/buhr/src/overflow/my-beam-project/src/Lib.hs, interpreted )
[2 of 2] Compiling Main ( /u/buhr/src/overflow/my-beam-project/app/Main.hs, interpreted )
Ok, two modules loaded.
Loaded GHCi configuration from /tmp/haskell-stack-ghci/e5a80991/ghci-script
*Main Lib> import Database.Beam
*Main Lib Database.Beam> :t fieldName
fieldName
:: Functor f =>
(text-1.2.3.1:Data.Text.Internal.Text
-> f text-1.2.3.1:Data.Text.Internal.Text)
-> TableField table ty -> f (TableField table ty)
*Main Lib Database.Beam>
and, of course, you can add code in src/Lib.hs and/or app/Main.hs using the beam-core package.
For question #4:
As noted in a comment, I believe the problem you're encountering is that the most recent LTS is lts-15.3, and beam-core is not currently being built for this snapshot.
Because beam-core was built for previous snapshots but isn't being built for the current snapshot, there's probably a good reason it's been left out. In this case, it looks like the maintainer has not upgraded it to work with the latest GHC versions. Specifically, the latest version of beam-core-0.8.0.0 requires a version of hashable < 1.3, but the latest version satisfying that constraint is hashable-1.2.7.0 which requires base < 4.13. And, while it's far from obvious, that means it doesn't work with GHC 8.8, only GHC 8.6, so you have to go back to a GHC 8.6-series Stackage snapshot.

Why can't I use Text.Regex in my Stack project?

All I want is to parse a simple string using regex.
First question: Should I be using Text.Regex or something else? Stackage lists at least 11 regex packages. I don't care if it's PCRE or Posix. At this point I'll accept anything.
Second Question: How do I include Text.Regex in my project? This is my experience so far:
package.yaml has
dependencies:
- base >= 4.7 && < 5
- regex
stacky.yaml attempt 1
extra-deps:
- regex-1.0.1.3
Response to stack build
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for regex-1.0.1.3:
base-compat-0.10.5 from stack configuration does not match >=0.6 && <0.10 (latest matching version is 0.9.3)
template-haskell-2.13.0.0 from stack configuration does not match >=2.7 && <2.12 (latest matching version is 2.11.1.0)
needed due to CCompiler-0.1.0.0 -> regex-1.0.1.3
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 /Users/adamfrank/Dev/Haskell/CCompiler/stack.yaml:
- base-compat-0.9.3
- template-haskell-2.11.1.0
Plan construction failed.
stack.yaml attempt 2
extra-deps:
- regex-1.0.1.3
- base-compat-0.9.3
- template-haskell-2.11.1.0
Response to stack build:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for regex-1.0.1.3:
template-haskell-2.13.0.0 from stack configuration does not match >=2.7 && <2.12 (latest matching version is 2.11.1.0)
needed due to CCompiler-0.1.0.0 -> regex-1.0.1.3
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 /Users/adamfrank/Dev/Haskell/CCompiler/stack.yaml:
- template-haskell-2.11.1.0
Plan construction failed.
???
It says I need to add a line I already added.
Do I need a different version of regex? If so, which one, and how do I figure that out?
There are a few recommendations in the comments as to what to use: regex-base, but it is also good to understand why it is not compiling.
Stackage provides a list of compatible packages in each LTS. You can alter some of the version numbers as long as they respect the version constraints of other dependencies. Not all of these dependency restrictions are well defined in the packages coming from Hackage, which is one of the reasons for using Stackage.
Generally each stackage major LTS release is associated with a particular version of GHC which also has a particular version of base. When you pick a major version of LTS, you are also picking a version of GHC and base. If you want to change GHC and/or base versions, it is easier to change the LTS version. The first thing after the LTS version on the Stackage LTS page is the GHC version number.
In your case regex requires a version of template-haskell and base-compat that violate the constraints of other dependencies.

Haskell dependency hell

I'm trying to include a specific version of a library in a Haskell project. The library is bed-and-breakfast (which is used for martix operations), but I need the specific version 0.4.3 which fixed a bug with the multiplication implementation.
So, my stack.yaml looks like this:
flags: {}
extra-package-dbs: []
packages:
- .
extra-deps:
- bed-and-breakfast-0.4
- base-4.6.0.1
resolver: lts-12.8
But I'm getting this error when building:
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for bed-and-breakfast-0.4:
base-4.11.1.0 from stack configuration does not match >=4.5 && <4.7 (latest matching version
is 4.6.0.1)
needed due to realworldhaskell-0.1.0.0 -> bed-and-breakfast-0.4
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 C:\Users\info\Desktop\Projects\haskell\stack.yaml:
- base-4.6.0.1
I've done the recommended action but it didn't solve anything. I've tried using different resolvers to see if it's an issue with my GHCi version but nothings worked. What is the best way to interpret error messages like this and how should I proceed?
EDIT:
If I remove -base.4.6.0.1 and add allow-newer: true I get this:
WARNING: Ignoring out of range dependency (allow-newer enabled): base-4.11.1.0. bed-and-breakfast requires: >=4.5 && <4.7
bed-and-breakfast-0.4: configure
Progress 1/2
-- While building custom Setup.hs for package bed-and-breakfast-0.4 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe --builddir=.stack-work\dist\7d103d30 configure --with-ghc=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\ghc-8.4.3\bin\ghc.EXE --with-g
hc-pkg=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\ghc-8.4.3\bin\ghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:\sr\snapshots\76fd1958\pkgdb --package-db=C:\Users\info\Desktop\Projects\haskell\
.stack-work\install\8c390635\pkgdb --libdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\lib --bindir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\bin --datadir=C:\Users\info\Desktop\Proj
ects\haskell\.stack-work\install\8c390635\share --libexecdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\libexec --sysconfdir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\etc --docdir=C:
\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --htmldir=C:\Users\info\Desktop\Projects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --haddockdir=C:\Users\info\Desktop\Pr
ojects\haskell\.stack-work\install\8c390635\doc\bed-and-breakfast-0.4 --dependency=array=array-0.5.2.0 --dependency=base=base-4.11.1.0 --dependency=binary=binary-0.8.5.1 --dependency=deepseq=deepseq-1.4.3.0 --dependency=template-hask
ell=template-haskell-2.13.0.0 --extra-include-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include --extra-lib-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\min
gw64\bin --extra-lib-dirs=C:\Users\info\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib --exact-configuration
Process exited with code: ExitFailure 1
Logs have been written to: C:\Users\info\Desktop\Projects\haskell\.stack-work\logs\bed-and-breakfast-0.4.log
Configuring bed-and-breakfast-0.4...
Cabal-simple_Z6RU0evB_2.2.0.1_ghc-8.4.3.exe: The package has an impossible
version range for a dependency on an internal library: bed-and-breakfast
==0.3.2. This version range does not include the current package, and must be
removed as the current package's library will always be used.
EDIT 2:
Ok, so I'm guessing that the bed-and-breakfast library needs base 4.11.1.0 which is included in GHCi 6.10.2 (according to https://wiki.haskell.org/Base_package) so I need a resolver which matches that GHCi version. Where can I find out what resolver version that is?
Here is the constraint on the latest available bed-and-breakfast package: base (>=4.5 && <4.7), which means it will likely not even compile with GHC version higher then 7.6. Considering that there is even no LTS snapshot prior to GHC 7.8, you are out of luck with that package.
To say it in another words, the package is outdated and your choices are:
submit an issue and hope maintainer will do something about it
try to make it work with newer ghc yourself
Use a different package

Haskell Web Framework

I'm creating simple web application using haskell. First I used Snap in front and I was able to run the application, but I want to add user input to the application.
I couldn't find a way to get user input parameters to the function. How might I do that?
Other thing, I also used Happstack framework, I can not import "Happstack.Server". I use cabal installation configure Happstack. It was successfully installed, but when I try to import to "Happstack.Server", it gives me an error:
<no location info>:
Could not find module `Happstack.Server':
it is not a module in the current program, or in any known package.
If I run my program using ghc --make HelloWorld.hs -v, I get:
Glasgow Haskell Compiler, Version 6.12.1, for Haskell 98, stage 2 booted by GHC version 6.12.1
Using binary package database: /usr/lib/ghc-6.12.1/package.conf.d/package.cache
Using binary package database: /home/udeshika/.ghc/i386-linux-6.12.1/package.conf.d/package.cache
package happstack-6.0.0-0f0c2507d590ebd01e8601c8667ec809 is unusable due to missing or recursive dependencies:
happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f network-bytestring-0.1.3.4-937fd511949a2d5ef21e86ec5306c791 sendfile-0.7.3-137cf51cc81a277d724637a7cd1e6b09
package happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9
package happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c is unusable due to missing or recursive dependencies:
hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f
package hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 is unusable due to missing or recursive dependencies:
...................
Snap's getParam function allows you to get HTTP request parameters specified by the user. These can come in the post body of a form submission or from the query string. For example, consider the following code:
site = dir "mypage" pageHandler
pageHandler = do
val <- getParam "foo"
writeBS $ maybe "no value" id val
If I request the url "myapp.com/mypage?foo=bar", then I will see "bar" as the response. If I leave off the "?foo=bar" part, then it will return "no value".
1) Check out that Happstack is actually installed and exposed:
ghc-pkg list | grep Happstack
2) What if you try to import Happstack.Server in ghci ?
3) Better use cabal-dev or capri for installing such things and making a sandbox
4) Snap and Yesod a quite new and they are under heavy development, Happstack is pretty
stable and solid.
5) What OS are you using? How did your installed the haskell? Ubuntu + haskell 6.12 + Happstack work out of the box
Regarding to the log, seems that cabal packages are messed up somehow. I recommend you to remove all packages from the .cabal and .ghc, reinstall cabal, then install cabal-dev as explained here:
http://www.reddit.com/r/haskell/comments/f3ykj/psa_use_cabaldev_to_solve_dependency_problems/
and then have fun with Happstack. Some guys actually use capri, it works as well.
Your installation is messed up. Unfortunately, cabal does that sometimes.
Your best bet is use 'ghc-pkg unregister ' to remove all the happstack packages, hslogger, and sendfile. Make sure they are removed from the user and global package databases. (ghc-pkg list will show you what is installed). Once you have the old versions removed, do, cabal update and the cabal install happstack. Then things should work.
What do you mean by 'user input' ? Do you mean html forms? Or something else ?
This section of the crash course may address your needs:
http://www.happstack.com/docs/crashcourse/RqData.html
It is also possible to use digestive-functors with Happstack to get type-safe form processing. Unfortunately, this is not well documented yet. Though I believe the disgestive-functors source code does include a working Happstack example.

Resources