Changes between Initial Version and Version 1 of Ticket #2734


Ignore:
Timestamp:
Oct 30, 2008 11:45:21 AM (5 years ago)
Author:
simonpj
Comment:

I'm afraid this is by design: the 6.6 deriving mechanism could all-too-easily infer a stupid context for the derived instance declaration.

However 6.10 lets you specify the context for the derived instance declaration (rather than having it inferred) thus:

 newtype Polynomial ord = P [Monomial ord] deriving (Eq,Show)

 deriving instance Ord (Monomial ord) => Ord (Polynomial ord)

The deriving instance is half way between deriving(Ord) and giving a full instance declaration, which you didn't want to do. It's documented under "standalone deriving" in the user manual.

If the documentation could be improved, I'd welcome concrete suggestions. Meanwhile I'm closing the bug.

Simon

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2734

    • Property Status changed from new to closed
    • Property Difficulty changed from to Unknown
    • Property Resolution changed from to invalid
  • Ticket #2734 – Description

    initial v1  
    11Consider the following code: 
    2  
     2{{{ 
    33{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} 
    44 
     
    2121instance Ord (Monomial ord) => Ord (Polynomial ord) where 
    2222    compare (P ts) (P us) = compare ts us 
    23  
     23}}} 
    2424In 6.6.1, it was permissible to derive the Ord instance for Polynomial ord from the ord instance for Monomial ord - the commented out code would compile. In 6.8.1-3, the commented out code doesn't compile, so you have to do the derivation by hand, as shown.