GHC rejects use of mulit-param type class.
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.
{-# 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'
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |