[GHC] #14484: GHC rejects use of mulit-param type class.

GHC ghc-devs at haskell.org
Sat Nov 18 02:22:35 UTC 2017


#14484: GHC rejects use of mulit-param type class.
-------------------------------------+-------------------------------------
           Reporter:  trinithis      |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.2
  (Type checker)                     |
           Keywords:                 |  Operating System:  Windows
       Architecture:                 |   Type of failure:  GHC rejects
  Unknown/Multiple                   |  valid program
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 In the following example, I instantiate a few small typeclasses. The last
 instantiation provided does not compile, despite it being virtually
 identical the prior instantiation.

 {{{#!hs
 {-# LANGUAGE FunctionalDependencies #-}
 {-# LANGUAGE MultiParamTypeClasses #-}

 --------------------------------------------------------------------------------

 class Collection collection handle | collection -> handle, handle ->
 collection where
     getHandles :: collection -> [handle]

 --------------------------------------------------------------------------------

 data HandleX = HandleX Int
 data CollectionX = CollectionX [HandleX]

 instance Collection CollectionX HandleX where
     getHandles (CollectionX handles) = handles

 --------------------------------------------------------------------------------

 newtype HandleY = HandleY HandleX
 newtype CollectionY = CollectionY CollectionX

 instance Collection CollectionY HandleY where
     getHandles (CollectionY collectionX) = map HandleY $ getHandles
 collectionX
     -- Good, this compiles!

 --------------------------------------------------------------------------------

 newtype HandleZ = HandleZ HandleY
 newtype CollectionZ = CollectionZ CollectionY

 instance Collection CollectionZ HandleZ where
     getHandle (CollectionZ collectionY) = map HandleZ $ getHandles
 collectionY
     -- Error: `getHandle' is not a (visible) method of class `Collection'
 }}}

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


More information about the ghc-tickets mailing list