Re: Proposal: Num instance for tuples
Dan Burton <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.libraries,gmane.comp.lang.haskell.cvs.ghc |
|---|---|
| Message-ID | <CALSygwcw-CEUJ0xFiCwb8+o7T930zfA4yf_5DqM3Ez33_z_kJQ@mail.gmail.com> |
> > One piece of utility code that I find myself writing over and over again > is the pointwise Num instance for tuples, i.e. > > instance (Num a, Num b) => Num (a,b) where > fromInteger x = (fromInteger x, fromInteger x) > (a,b) + (a',b') = (a + a', b + b') > (a,b) - (a',b') = (a - a', b - b') > (a,b) * (a',b') = (a * a', b * b') > negate (a,b) = (negate a, negate b) > abs (a,b) = (abs a, abs b) > signum (a,b) = (signum a, signum b) > > I therefore propose that this instance be added to the base library. If we > do that, the equivalent instances for (,,) (,,,) etc. should perhaps also > be added, as well as instances for other numeric classes such as Fractional > and Floating. > -1 from me. While this is a sensible instance, it has the potential to cause great confusion. It will make bug hunting that much harder when you accidentally put a numeric literal where a tuple of distinct numbers is supposed to be. Put the instance in its own package, and those that want it can just install the package. -- Dan Burton _______________________________________________ Libraries mailing list [email protected] http://www.haskell.org/mailman/listinfo/libraries