2

I've been playing with newtype wrappers for my indexes to avoid bugs, and I have some code like this:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

newtype PersonIdx = PersonIdx Int
  deriving (Enum, Eq, Integral, Num, Ord, Real, Show)

To derive Integral, one must derive all its dependencies as well (hence the above list of type-classes).

Is there a way to make it derive all the dependencies of Integral along with it? I would imagine something like:

newtype PersonIdx = PersonIdx Int
  deriving (Integral(..))
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
yairchu
  • 23,680
  • 7
  • 69
  • 109

1 Answers1

6

No, there is no shortcut. You'll have to derive from all dependent typeclasses explicitly, but can easily find these by typing :i Integral in ghci.

Dario
  • 48,658
  • 8
  • 97
  • 130
  • 2
    I wonder if there's a principled reason for this, or simply that no one has implemented the shortcut in question. – Phil Miller Jan 18 '10 at 18:03
  • It is somewhat in the philosophy of Haskell that everything be explicit. There are very few "shortcuts" in the language, and this example is no exception. – Martijn Jan 19 '10 at 10:15