Is there a function \x -> (x, x) in standard libraries?

Theodore Lief Gannon tanuki at gmail.com
Tue Jul 16 22:30:15 UTC 2019


Note that there is already a function named dup in base [1], albeit in
what's probably a low-traffic module (GHC.IO.Device).

As an alternative I would suggest twin, which returns no results from
Stackage Hoogle.

On the other hand, I'm roughly -0.5 on adding this at all; what use case
does it serve that's not better handled with &&&? (Those 22 occurences of id
&&& id seem most likely to provide illumination...)

[1]:
https://hackage.haskell.org/package/base-4.5.1.0/docs/GHC-IO-Device.html#v:dup

On Tue, Jul 16, 2019 at 2:22 PM Dan Burton <danburton.email at gmail.com>
wrote:

> +1 for "dup", if it is to be included at all.
>
> -- Dan Burton
>
>
> On Tue, Jul 16, 2019 at 12:56 PM Vladislav Zavialov <vladislav at serokell.io>
> wrote:
>
>> It is reasonably common. I have grepped Hackage using
>> https://codesearch.aelve.com/haskell/ and
>>
>> * \x->(x,x) occurs 203 times
>> * join (,) occurs 53 times
>> * id &&& id occurs 22 times
>>
>> It also pops up in discussions as a counter-example of a linear function:
>>
>> dup :: a ->. (a,a)
>> dup x = (x,x)  -- does not typecheck with -XLinearTypes!
>>
>> I think it should be added under the name "dup" (short for “duplicate”).
>>
>> - Vlad
>>
>> > On 16 Jul 2019, at 22:29, Lennart Augustsson <lennart at augustsson.net>
>> wrote:
>> >
>> > It's not harmful, but is it common enough to have a name?
>> >
>> > On Tue, Jul 16, 2019, 12:28 Ignat Insarov <kindaro at gmail.com> wrote:
>> > So, it is not considered harmful. Then I propose we add it to
>> > Data.Tuple under a humane name.
>> >
>> > On Tue, 16 Jul 2019 at 19:41, Lennart Augustsson <
>> lennart at augustsson.net> wrote:
>> > >
>> > > Or 'join (,)'
>> > >
>> > > On Tue, Jul 16, 2019, 09:26 Zemyla <zemyla at gmail.com> wrote:
>> > >>
>> > >> id &&& id
>> > >>
>> > >> On Tue, Jul 16, 2019, 10:58 Ignat Insarov <kindaro at gmail.com> wrote:
>> > >>>
>> > >>> Hello.
>> > >>>
>> > >>> I wonder if there is a function like \x -> (x, x) in the standard
>> libraries.
>> > >>>
>> > >>> I looked up in Hoogle. It gave me links:
>> > >>>
>> > >>> 1.
>> https://hackage.haskell.org/package/utility-ht/docs/Data-Tuple-HT.html#v:double
>> > >>> 2.
>> https://hackage.haskell.org/package/extra/docs/Data-Tuple-Extra.html#v:dupe
>> > >>> 3.
>> https://hackage.haskell.org/package/relude/docs/Relude-Extra-Tuple.html#v:dupe
>> > >>>
>> > >>> None of these is to the standard library. I wonder if there is an
>> > >>> intentional omission for some important reason? If not, I think this
>> > >>> function should be added to Data.Tuple.
>> > >>>
>> > >>> I know some of the persons that make decisions here like Category
>> > >>> theory, so I point out this function is mentioned in Categories for
>> > >>> the Working Mathematician, as δ, the diagonal function, on page 3
>> > >>> (second edition), although set with angular brackets.
>> > >>>
>> > >>> Have a great day.
>> > >>> _______________________________________________
>> > >>> Libraries mailing list
>> > >>> Libraries at haskell.org
>> > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> > >>
>> > >> _______________________________________________
>> > >> Libraries mailing list
>> > >> Libraries at haskell.org
>> > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> > _______________________________________________
>> > Libraries mailing list
>> > Libraries at haskell.org
>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190716/d7d94e07/attachment.html>


More information about the Libraries mailing list