[Haskell-cafe] Could not deduce ... using functional dependencies with GHC7
dimitris at microsoft.com
Fri Mar 18 12:56:14 CET 2011
Hi, can you elaborate a bit? What is Id and what is (Sig id) and IdSig in your
example? Can you reproduce an example that you believe should compile but doesn't?
From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of JP Moresmau
Sent: 16 March 2011 21:46
To: Haskell Cafe
Subject: [Haskell-cafe] Could not deduce ... using functional dependencies with GHC7
Hello, when moving to GHC7 a body of code that I'm not immensely familiar with, I got an error compiling with GHC 7.0.2. Can somebody kindly explain to me what it means and how to get around it?
This is in the scion code base so is using some GHC types.
I have a class with a functional dependency (I think :-p):
class Search id a | a -> id where
search :: (SrcSpan -> Bool) -> SrcSpan -> a -> SearchResults id
And some instances, notably:
instance Search Id Id where
search _ _ i = only (FoundId i)
And the error occurs on another instance:
instance (Search id id) => Search id (Sig id) where
search p s (IdSig i) = search p s i
... other cases here, that work
The error is:
Could not deduce (id ~ Id)
from the context (Search id id)
bound by the instance declaration
`id' is a rigid type variable bound by
the instance declaration at lib\Scion\Inspect\Find.hs:477:18
When using functional dependencies to combine
Search Id Id,
arising from the dependency `a -> id'
in the instance declaration at lib\Scion\Inspect\Find.hs:183:10
Search id Id,
arising from a use of `search'
In the expression: search p s i
In an equation for `search': search p s (IdSig i) = search p s i
If I replace the call to search with the actual implementation of search for Id, it compiles, so at some level the code "makes sense".
I much prefer when error messages end with "Possible fix:..."!
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
More information about the Haskell-Cafe