[GHC] #9918: GHC chooses an instance between two overlapping, but cannot resolve a clause within the similar closed type family

GHC ghc-devs at haskell.org
Mon Dec 22 11:42:47 UTC 2014


#9918: GHC chooses an instance between two overlapping, but cannot resolve a
clause within the similar closed type family
-------------------------------------+-------------------------------------
              Reporter:  qnikst      |            Owner:
                  Type:  bug         |           Status:  new
              Priority:  normal      |        Milestone:
             Component:  Compiler    |          Version:  7.8.3
            Resolution:              |         Keywords:
      Operating System:              |     Architecture:  Unknown/Multiple
  Unknown/Multiple                   |       Difficulty:  Unknown
       Type of failure:              |       Blocked By:
  None/Unknown                       |  Related Tickets:
             Test Case:              |
              Blocking:              |
Differential Revisions:              |
-------------------------------------+-------------------------------------

Comment (by qnikst):

 Sorry. Yes I can describe better.

 What we are trying to do:

 I have a code that uses monadic regions `IORT` and I want to write a
 function that allow to use a values from parent regions inside it's
 children `shPutStrLn`. In order to do it I need to write a type class
 `class (Monad m1, Monad m2) => MonadRaise m1 m2 where lifts :: m1 a -> m2
 a` that allow me to lift actions from one monad to another.

 One solution is to use Overlapping instances (lines 44-51) and it works
 perfectly.

 Changes:

 The idea was to provide a solution that doesn't require
 OverlappingInstances and uses closed type families to implement
 `MonadRaise` instead, lines 22-39.

 The idea was to provide a type family `TEQ` that describes an equality*
 between
 monad stacks. equality* - is because we constraint the form of stacks a
 bit.
 Instead of having 2 Overlapping instances now we have one that calls a
 method
 from no-longer overlapping instance `MonadRaise'` and provides a proxy
 that
 is an evidence of our equality*.

 It worked for all but one tests in our suite. The problem here is that
 `MonadRaise'`
 instance can't be deduced now (with or without adding explicit type
 signature to the test method):

 {{{
 Minimal.hs:58:12:
     Could not deduce (MonadRaise'
                         (TEQ (IORT s' m') (IORT s (IORT s' m')))
                         (IORT s' m')
                         (IORT s (IORT s' m')))
       arising from a use of ‘shPutStrLn’
 }}}

 Why I think it should work:

 I think that it could be possible to deduce MonadRaise' instance because
 `TEQ (IORT s' m') (IORT s (IORT s' m')` is `False` due to expression on
 line 24.
 and we have corresponding instance:

 `instance (Monad m2, m2 ~ (IORT s m2'), MonadRaise m1 m2') => MonadRaise'
 False m1 m2 where`
 line 37.

 As a result it seems that compiler have all information for selecting an
 instance of
 `MonadRaise' False m1 m2` and thus `MonadRaise m1 m2`.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9918#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list