I’m trying to build an app based on gitlib
and want to write a little additional function with this type signature: MonadGit r m => m [RefName]
. It’s the same as gitlib
‘s own listReferences
, so I’ll be using that as an example:
module Foo where
import Conduit
import Git.Types
listReferences :: MonadGit r m => m [RefName]
listReferences = runConduit $ sourceReferences .| sinkList
This compiles as expected using $ ghc Reference.hs
within nix-shell -p 'ghc.withPackages (p: with p; [ gitlib-libgit2 ])'
However, in the same file I also need to use Git.Libgit2
which I do as a qualified import like this:
module Foo where
import Conduit
import Git.Types
import qualified Git.Libgit2 as LG
listReferences :: MonadGit r m => m [RefName]
listReferences = runConduit $ sourceReferences .| sinkList
This no longer compiles, throwing the following error:
$ ghc Reference.hs
[1 of 1] Compiling Foo ( Reference.hs, Reference.o ) [Source file changed]
Reference.hs:7:19: error: [GHC-25897]
• Couldn't match type ‘r’ with ‘LG.LgRepo’
arising from a functional dependency between constraints:
‘MonadGit LG.LgRepo m’
arising from a type ambiguity check for
the type signature for ‘listReferences’ at Reference.hs:7:19-45
‘MonadGit r m’
arising from the type signature for:
listReferences :: forall r (m :: * -> *).
MonadGit r m =>
m [RefName] at Reference.hs:7:19-45
‘r’ is a rigid type variable bound by
the type signature for:
listReferences :: forall r (m :: * -> *).
MonadGit r m =>
m [RefName]
at Reference.hs:7:19-45
• In the ambiguity check for ‘listReferences’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
listReferences :: MonadGit r m => m [RefName]
|
7 | listReferences :: MonadGit r m => m [RefName]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
What is even going on here; why is it trying to match the type with some other type that I’m not even using anywhere? (Linter confirms the import is unused.)
How can I solve this issue?