[GHC] #10778: GHC doesn't infer all constrains
GHC
ghc-devs at haskell.org
Tue Aug 18 10:37:53 UTC 2015
#10778: GHC doesn't infer all constrains
-------------------------------------+-------------------------------------
Reporter: danilo2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Description changed by danilo2:
Old description:
> Hello! Let's consider following signatures:
> {{{
> class (IndexOf a cont ~ idx, ElementByIdx idx cont ~ a, Measurable cont)
> => Container cont idx a
> class Container cont idx a => Appendable cont idx a
> class HasContainer a cont | a -> cont
> class Monad m => RefBuilder3 a m ref | a m -> ref where
> mkRef3 :: a -> m (ref a)
>
> }}}
>
> Now when I define following instance:
>
> {{{
> instance (PtrFrom idx i, Appendable cont idx a, HasContainer g cont,
> Monad m)
> => RefBuilder3 a (GraphBuilderT g m) (Ptr i) where
> mkRef3 = undefined
> }}}
>
> I get an error:
>
> {{{
> Illegal instance declaration for
> ‘RefBuilder3 a (GraphBuilderT g m) (Ptr i)’
> The liberal coverage condition fails in class ‘RefBuilder3’
> for functional dependency: ‘a m -> ref’
> Reason: lhs types ‘a’, ‘GraphBuilderT g m’
> do not jointly determine rhs type ‘Ptr i’
> In the instance declaration for
> ‘RefBuilder3 a (GraphBuilderT g m) (Ptr i)’
> }}}
>
> But when I add the constraint to the instance head:
>
> {{{
> instance (PtrFrom idx i, Appendable cont idx a, HasContainer g cont,
> Monad m, IndexOf a cont ~ idx)
> => RefBuilder3 a (GraphBuilderT g m) (Ptr i) where
> mkRef3 a = fmap ptrFrom . withGraph . append $ a
> }}}
>
> It compiles fine. What's interesting, the constraint should be inferred
> by GHC, because we've got following funds here:
> {{{
> g -> cont -- from HasContainer
> cont a -> idx -- from Appendable -> Container
> }}}
>
> Is this a GHC bug or am I missing something? If thats a bug, I will try
> to clean the code and make a minimal example.
New description:
Hello! Let's consider following signatures:
{{{
class (IndexOf a cont ~ idx, ElementByIdx idx cont ~ a, Measurable cont)
=> Container cont idx a
class Container cont idx a => Appendable cont idx a
class HasContainer a cont | a -> cont
class PtrFrom p i | p -> i
class Monad m => RefBuilder3 a m ref | a m -> ref where
mkRef3 :: a -> m (ref a)
}}}
Now when I define following instance:
{{{
instance (PtrFrom idx i, Appendable cont idx a, HasContainer g cont, Monad
m)
=> RefBuilder3 a (GraphBuilderT g m) (Ptr i) where
mkRef3 = undefined
}}}
I get an error:
{{{
Illegal instance declaration for
‘RefBuilder3 a (GraphBuilderT g m) (Ptr i)’
The liberal coverage condition fails in class ‘RefBuilder3’
for functional dependency: ‘a m -> ref’
Reason: lhs types ‘a’, ‘GraphBuilderT g m’
do not jointly determine rhs type ‘Ptr i’
In the instance declaration for
‘RefBuilder3 a (GraphBuilderT g m) (Ptr i)’
}}}
But when I add the constraint to the instance head:
{{{
instance (PtrFrom idx i, Appendable cont idx a, HasContainer g cont, Monad
m, IndexOf a cont ~ idx)
=> RefBuilder3 a (GraphBuilderT g m) (Ptr i) where
mkRef3 a = fmap ptrFrom . withGraph . append $ a
}}}
It compiles fine. What's interesting, the constraint should be inferred by
GHC, because we've got following funds here:
{{{
g -> cont -- from HasContainer
cont a -> idx -- from Appendable -> Container
idx -> i -- from PtrFrom
}}}
Is this a GHC bug or am I missing something? If thats a bug, I will try to
clean the code and make a minimal example.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10778#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list