Proposal: Num instance for tuples
anton.nik at gmail.com
Fri Oct 19 12:17:28 CEST 2012
Brent Yorgey <byorgey at seas.upenn.edu> writes:
> On Thu, Oct 18, 2012 at 11:58:17AM +0200, Twan van Laarhoven wrote:
>> Dear list,
>> 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.
> I am +1 for this proposal, but only as long as these instances are not
> exported by the Prelude. They are useful when you know you want them
> but will confuse newbies -- based on evidence from #haskell, where
> lambdabot has such instances in scope.
So, put it in a package. It has nothing to do in the Prelude.
More information about the Libraries