Acid-State example compiled error. No No instance for (Control.Monad.Reader.Class.MonadReader FailureDb (Query FailureDb)) - haskell

I was trying acid example but compile error.
The error message says no instance No instance for MonadState, No instance for MonadReader.
This article says it is due to two different mtl versions installed.
And I am using nix-shell in nixos:
ghc-pkg list | grep acid
acid-state-0.14.3
ghc-pkg list | grep mtl
mtl-2.2.1
mtl-2.2.2
However, if I don't use acid-state package when I enter nix-shell, I got:
ghc-pkg list | grep mtl
mtl-2.2.2
That probably means acid-state is using different mtl version than Control.Monad.Reader.
But acid-state's stack.yaml in github is lts-11.15, which has mtl-2.2.2.
So what should I do to make it work?

Stack and Cabal-install have similar problems when dealing with GHC's package dbs, but these problems can be avoided:
Stack
When I use Stack, I don't run it in a nix-shell, so that the nix-shell can't add packages to the wrapped GHC command that Stack will then consider to be system packages ('global' in Cabal terminology). I am not sure whether this is the only valid approach though.
Cabal-install only
When calling Cabal in a nix-shell, you should add these flags to prevent GHC from looking at the wrong package db: cabal configure --package-db=clear --package-db=global. The GHC wrapper will make the Nix-managed dependencies appear in the 'global' package db.

Related

With HaskellStack install packages to use with GHC without stack

I install GHC on Windows10 using the recommended Haskell Stack. I want to us GHC without all the Stack overhead for Advent of Code. This was working fine until I tried to get the extra package.
I can install it with Stack, but I don't seem to have a way to get it in the global package database. Haskell Stack apparently does not install the cabal executable and seems to have it locked out of their package database.
How do I install the extra package for use with vanilla GHC?
John Miller#DESKTOP-NENAGQH MSYS /d/dev/AdventOfCode2020
$ stack ghc -- AoC/Utils.hs
[1 of 1] Compiling AoC.Utils ( AoC\Utils.hs, AoC\Utils.o )
John Miller#DESKTOP-NENAGQH MSYS /d/dev/AdventOfCode2020
$ ghc AoC/Utils.hs
[1 of 1] Compiling AoC.Utils ( AoC\Utils.hs, AoC\Utils.o ) [Data.List.Extra changed]
AoC\Utils.hs:3:1: error:
Could not find module `Data.List.Extra'
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Data.List.Extra
| ^^^^^^^^^^^^^^^^^^^^^^
I don't know whether stack supports installing to the global package DB. cabal does though:
$ cabal install --lib extra
Resolving dependencies...
Up to date
$ ghci
GHCi, version 8.10.2: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /home/simon/.ghc/x86_64-linux-8.10.2/environments/default
Prelude> import Data.List.Extra
Prelude Data.List.Extra>
Ok, so stack can install the cabal executable if you beat at it long enough. The package is called cabal-install and it is not in any resolver, but is on Hackage.
stack install cabal-install
Because it is not in the resolver there is a pretty good chance that the version of Cabal, the library for manipulating cabal packages in Haskell, is not compatible. First, ask stack where it keeps its global config
stack path --config-location
Edit that file to allow for the needed dependencies under extra-deps: Stack will helpfully tell you what they are. It may also be helpful to change the resolver to a newer version in that file while your at it.
Now try
stack install cabal-install
again and if these instructions have not fallen out of date since December 2020 you will get the cabal executable somewhere potentially useful.
Before using cabal you will have to run a cabal update to get the package list.
At this point cabal should manipulate your global package database and stack can install GCH and all its libraries over and over and over again if you want to use it for a project instead. They should just keep out of each other's way.

How to generate a ghc database for one package?

I want to use GHC_PACKAGE_PATH to point at several ghc package databases (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-databases).
I have one haskell library in ~/mylib and would like to generate a database that contains this package ~/mylib.
I have tried
ghc-pkg -v -f ~/mylib recache
but the generated package.cache is empty and thus ghc-pkg -v list does show me the database but with an empty package list.
NB:There is a cabal file in ~/mylib/mylib.cabal
To answer myself, cabal build generates such a db in dist/package.conf.inplace/ that can then be referred to via cabal configure --package-db /home/teto/netlink-hs/dist/package.conf.inplace

How to use cabal install for regular expression package installation?

Am working through Real World Haskell and am trying to install regex-posix-0.95.2 from an untar[ed] package by simplying running
cabal install
I then see:
Text/Regex/Posix/Wrap.hsc:141:1: error:
Could not find module ‘Text.Regex.Base.RegexLike’
There are files missing in the ‘regex-base-0.93.2’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
141 | import Text.Regex.Base.RegexLike(RegexOptions(..),RegexMaker(..),RegexContext(..),MatchArray)
Despite the fact that I can load this in ghci with
Prelude> :module Text.Regex.Base.RegexLike
Prelude Text.Regex.Base.RegexLike>
Prelude> import Text.Regex.Base.RegexLike(RegexOptions(..),RegexMaker(..),RegexContext(..),MatchArray)
Prelude Text.Regex.Base.RegexLike>
and see it in the module-system.
[warrick#warrick-pc regex-posix-0.95.2]$ ghc-pkg find-module Text.Regex.Base.RegexLike
/usr/lib/ghc-8.6.2/package.conf.d
regex-base-0.93.2
Why is this failing?
What are some more general tips and tricks when trying to debug cabal failures you'd recommend (as this is one instance of many issues I'm consistently having with Cabal)?
This is a linking issue. For example, some distributions like Arch use dynamic linking by default, without static libraries, but without additional configuration, cabal tries to link statically, which results in the kind of message you are seeing. For more information: https://wiki.archlinux.org/index.php/Haskell

Haskell packages not listed in ghc-pkg when installed through Nix

I have installed GHC through Nix:
$ nix-env -i ghc
Then I have installed the aeson package:
$ nix-env -f "<nixpkgs>" -iA haskellPackages.aeson
And pointed GHC to the Nix package folder:
$ export GHC_PACKAGE_PATH=~/.nix-profile/lib/ghc-8.0.1/package.conf.d/
Which seems to work:
$ ghc-pkg list
/Users/zoul/.nix-profile/lib/ghc-8.0.1/package.conf.d
Cabal-1.24.0.0
array-0.5.1.1
…
But the aeson package is missing from the list of packages above and can’t be loaded. Even though there’s clearly something there:
$ ls /Users/zoul/.nix-profile/lib/ghc-8.0.1/ | grep ^ae
aeson-0.11.2.1
What am I doing wrong?
You cannot install Haskell libraries in Nix that way because the ghc compiler you're using does not search your user's profile for libraries. Consequently, installing a library there has no effect. This topic is explained in great detail in the Nixpkgs user manual. I'm citing the relevant bit from "8.5.2.2. How to install a compiler with libraries":
GHC expects to find all installed libraries inside of its own lib directory. This approach works fine on traditional Unix systems, but it doesn’t work for Nix, because GHC’s store path is immutable once it’s built. We cannot install additional libraries into that location. As a consequence, our copies of GHC don’t know any packages except their own core libraries, like base, containers, Cabal, etc.
We can register additional libraries to GHC, however, using a special build function called ghcWithPackages. That function expects one argument: a function that maps from an attribute set of Haskell packages to a list of packages, which determines the libraries known to that particular version of GHC. For example, the Nix expression ghcWithPackages (pkgs: [pkgs.mtl]) generates a copy of GHC that has the mtl library registered in addition to its normal core packages:
$ nix-shell -p "haskellPackages.ghcWithPackages (pkgs: [pkgs.mtl])"
[nix-shell:~]$ ghc-pkg list mtl
/nix/store/zy79...-ghc-7.10.2/lib/ghc-7.10.2/package.conf.d:
mtl-2.2.1
This function allows users to define their own development environment by means of an override. After adding the following snippet to ~/.nixpkgs/config.nix,
{
packageOverrides = super: let self = super.pkgs; in
{
myHaskellEnv = self.haskell.packages.ghc7102.ghcWithPackages
(haskellPackages: with haskellPackages; [
# libraries
arrows async cgi criterion
# tools
cabal-install haskintex
]);
};
}
it’s possible to install that compiler with nix-env -f "<nixpkgs>" -iA myHaskellEnv.

Persistent modules not found

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.

Resources