[GHC] #8634: Relax functional dependency coherence check ("liberal coverage condition")

GHC ghc-devs at haskell.org
Mon Jul 21 19:47:38 UTC 2014


#8634: Relax functional dependency coherence check ("liberal coverage condition")
-------------------------------------+-------------------------------------
              Reporter:  danilo2     |             Owner:
                  Type:  feature     |            Status:  new
  request                            |         Milestone:  7.10.1
              Priority:  high        |           Version:  7.7
             Component:  Compiler    |          Keywords:
            Resolution:              |  Operating System:  Unknown/Multiple
Differential Revisions:  Phab:D69    |   Type of failure:  None/Unknown
          Architecture:              |         Test Case:
  Unknown/Multiple                   |          Blocking:
            Difficulty:  Unknown     |
            Blocked By:              |
       Related Tickets:  #1241,      |
  #2247, #8356, #9103, #9227         |
-------------------------------------+-------------------------------------

Comment (by danilo2):

 @diatchki - you are right - in this simple example your solution would
 work and will fulfill the LCC (Liberal Coverage Condition). Again - trying
 to simplify examples, they got oversimplified sometimes. I will try to put
 here another one, a little more complex:
 {{{#!haskell
 {-# LANGUAGE NoMonomorphismRestriction #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
 {-# LANGUAGE FunctionalDependencies #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE DysfunctionalDependencies #-}

 class Property a b | a -> b where
    property :: a -> b

 data X = X
 data Y = Y

 instance Monad m => Property X Y where
     prperty _ = Y

 instance Monad m => Property Y (m Int) where
     property _ = return 5

 main = do
     let f = property $ property X
     -- ... some code here
     print "end"
 }}}

 Let assume the above code is generated an **rarely** there is situation
 that the LCC condition is not met (as with the second instance). Property
 is just an associated object with current one. We want to create chains of
 associated objects, like `property $ property $ property Z`. To do so, we
 have to use functional dependencies. Additional there is no way of
 checking if such chain violates or not the LCC. This is the users
 responsibility (I can explain this further if needed). Sometimes it could
 happen, that LCC would be not met, as I showed above, but it still (!)
 tells:

 "Aha, there is a functional relation between the parameters of this class.
 This means that whenever the first parameters of instances are the same,
 so will be the second ones."

 and this is still true for `-XDysfunctionalDependencies`! The difference
 is, as shown by @sulzmann, that the Coverage Condition is completely
 lifted.

 The above example is still very, very simplified and does not show the
 complex of the problem, but as I mentioned above - we have moved
 succesfully our code from GHC 7.6 into GHC 7.10(head) with the extension
 of `-XDysfunctionalDependencies` and it just works (even with large
 "connection chains" (mentioned above). I think it just works in this
 scenario and still, the fundeps are talking to as, that whenever the first
 parameters are the same, so will be the second ones. One thing that is not
 so beautifull is the name - I do not know if `-XDysfunctionalDependencies`
 or `-XUndecidableInstances` are proper names for their behaviours.

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


More information about the ghc-tickets mailing list