Proposal: Num instance for tuples
Conal Elliott
conal at conal.net
Thu Oct 25 01:25:57 CEST 2012
I use these instances and similar ones from NumInstances [1] quite a bit. I
also frequently use another pattern for applicative functors, via
applicative-numbers [2]. I don't mind pulling these instances from a
package, though they are orphans.
It does trouble me a bit that the two patterns overlap and disagree on
pairs.
For pairs, I like fromInteger n = (fromInteger n, fromInteger n). Then, for
instance, 1 * (a,b) = (a,b).
-- Conal
[1] http://hackage.haskell.org/package/NumInstances
[2] http://hackage.haskell.org/package/applicative-numbers
On Thu, Oct 18, 2012 at 2:58 AM, Twan van Laarhoven <twanvl at gmail.com>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.
>
>
> Discussion period: 2 weeks, ends 2012-11-01.
>
>
> Twan
>
> ______________________________**_________________
> Cvs-ghc mailing list
> Cvs-ghc at haskell.org
> http://www.haskell.org/**mailman/listinfo/cvs-ghc<http://www.haskell.org/mailman/listinfo/cvs-ghc>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20121024/e56528a5/attachment.htm>
More information about the Libraries
mailing list