问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/52108291/acid-state-example-compiled-error-no-no-instance-for-control-monad-reader-clas