Re: Proposal: Num instance for tuples

Conal Elliott <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc,gmane.comp.lang.haskell.libraries
Message-ID <CAD6SzRL2t1ozAU=sHEctRNWhziDJafFMvFE56MSs2P5kwoJ42g@mail.gmail.com>
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 <[email protected]>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
> [email protected]
> http://www.haskell.org/**mailman/listinfo/cvs-ghc<http://www.haskell.org/mailman/listinfo/cvs-ghc>
>

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.