#5677: Allow the definition of extra functions in typeclass instances
---------------------------------+------------------------------------------
    Reporter:  FUZxxl            |       Owner:                              
        Type:  feature request   |      Status:  new                         
    Priority:  normal            |   Component:  Compiler                    
     Version:  7.2.1             |    Keywords:  instance typeclass extension
    Testcase:                    |   Blockedby:                              
          Os:  Unknown/Multiple  |    Blocking:                              
Architecture:  Unknown/Multiple  |     Failure:  GHC rejects valid program   
---------------------------------+------------------------------------------
 It would be nice, if one could define functions in an instance declaration
 that don't exist in the corresponding typeclass. Such a function should be
 only visible to the functions in the instance it is defined in.

 I can imagine two purposes for such functions:

 Consider a library MyLib that has a typeclass Foo. In version 1.0 of the
 library, Foo is defined as:

 {{{
 class Foo a where
   foo :: ...
   bar :: ...
 }}}

 but in version 2.0, an additional member baz was added. If you want to
 write an instance of Foo that works both on 1.0 and 2.0, you currently
 have to use the preprocessor to hide the definition of baz if linked
 against library version 1.0. It would make writing code that works with
 multiple versions of other libraries much easier, if an extranous function
 in an instance is allowed.

 The other purpose is that one can put common code of member functions in
 an extra function without moving the code out of the instance body.
 Together with ScopedTypeVariables, this might turn out to be pretty
 useful.

 As an addition, I would recommend to add a warning for the case, that an
 instance declares a function that is neither present in the class
 declaration nor used in the instance itself. This would catch most simple
 errors.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to