[Haskell-cafe] Re: Type classes: Missing language feature?

apfelmus apfelmus at quantentunnel.de
Tue Aug 7 09:46:16 EDT 2007

DavidA wrote:
> newtype Lex = Lex Monomial deriving (Eq)
> newtype Glex = Glex Monomial deriving (Eq)
> Now, what I'd like to do is have Lex and Glex, and any further monomial 
> orderings I define later, automatically derive Show and Num instances from 
> Monomial (because it seems like boilerplate to have to define Show and Num 
> instances by hand).

Good news: it's already implemented and called newtype deriving :)


In short, you just write

 newtype Lex = Lex Monomial deriving (Eq, Show, Num)

I guess that the Show instance will add the constructor Lex , though.


More information about the Haskell-Cafe mailing list