Proposal: Add conspicuously missing Functor instances for tuples
amindfv at gmail.com
amindfv at gmail.com
Tue Jan 19 21:50:37 UTC 2016
> El 19 ene 2016, a las 16:22, Christopher Allen <cma at bitemyapp.com> escribió:
>
> >Why I'm not quite convinced about large tuples being entirely silly:
>
> They happen to be a useful dumb type for things like rows you parse from a csv file or similar as well. Pretty sure the various *-simple database clients use this as well.
>
In these cases large tuples are useful, but a Functor instance that operates on the last element?
> They are, admittedly, sort of a paradigm case for why `lens` is often more useful than Functors, but Functor isn't going anywhere and there's only one valid instance for these types so they might as well live with the types or the class.
>
My disagreement is only in "might as well": there is a downside to these, so I'd like there to be an upside (that's worth it!).
Tom
>> On Tue, Jan 19, 2016 at 3:20 PM, David Feuer <david.feuer at gmail.com> wrote:
>> The problem, I think, is that
>>
>> 1. Many of us thing the instance for pairs is useful. Some of us think
>> the instance for triples is occasionally useful. Most of us doubt the
>> instances for large tuples are often useful (but I'm not quite
>> convinced).
>> 2. Most of us value consistency very highly. Even if we think the
>> instance for pairs is great and the instance for septuples is silly,
>> we want to have the same answer for all tuple sizes.
>>
>> Thus we have the usual "The axiom of choice is obviously true, the
>> well-ordering principle is obviously false, and who can say about
>> Zorn's lemma."
>>
>> Why I'm not quite convinced about large tuples being entirely silly:
>> people do weird things with Template Haskell. When they do so, they
>> want to be able to use functions as uniformly as possible. A function
>> (fmap) that always hits the last component of a tuple, even if it has
>> 15 components, may be just what they need.
>>
>> On Tue, Jan 19, 2016 at 4:04 PM, <amindfv at gmail.com> wrote:
>> > If the only uses we can imagine for these instances are
>> > - Cases where it's not a great design decision
>> > - Cases where it's used accidentally and results in a silent runtime
>> > failure instead of a compile-time error
>> >
>> > then I'm a strong -1
>> >
>> > Tom
>> >
>> > El 19 ene 2016, a las 15:54, Alois Cochard <alois.cochard at gmail.com>
>> > escribió:
>> >
>> > I don't have any use case like that. I'm in favor of this proposal for
>> > consistency sake.
>> >
>> > That last part of my comment about usefulness/discouraging usage was about
>> > using Functor instance on tuple in general, no matter the arity.
>> >
>> > On 19 January 2016 at 21:32, <amindfv at gmail.com> wrote:
>> >>
>> >> El 19 ene 2016, a las 10:24, Alois Cochard <alois.cochard at gmail.com>
>> >> escribió:
>> >>
>> >> +1
>> >>
>> >> Agree for consistency, I can also see those instances as being useful in
>> >> some specific context, even if I agree with Andreas that in general they
>> >> should be discouraged (especially for newcomers).
>> >>
>> >>
>> >> Can you give us an example where using e.g. the Functor instance for a
>> >> 5-tuple would be the correct/best design decision?
>> >>
>> >> Tom
>> >>
>> >>
>> >>
>> >> On 19 January 2016 at 09:20, Herbert Valerio Riedel <hvriedel at gmail.com>
>> >> wrote:
>> >>>
>> >>> On 2016-01-18 at 21:10:07 +0100, David Feuer wrote:
>> >>> > For some reason I really can't imagine, it seems the only tuple type
>> >>> > with a Functor instance is (,) a. I was astonished to find that
>> >>> >
>> >>> > fmap (+1) (1,2,3)
>> >>> >
>> >>> > doesn't work. Since this is *useful*, and there is *only one way to do
>> >>> > it*, I propose we add the following:
>> >>> >
>> >>> > instance Functor ((,,) a b) where
>> >>> > fmap f (a,b,c) = (a,b,f c)
>> >>> > instance Functor ((,,,) a b c) where
>> >>> > fmap f (a,b,c,d) = (a,b,c,f d)
>> >>> > etc.
>> >>>
>> >>> As stated elsewhere in this thread already, there is the issue about
>> >>> consistency. Here's a relevant section from the Haskell 2010 report[1]:
>> >>>
>> >>> > 6.1.4 Tuples
>> >>> >
>> >>> > ...
>> >>> >
>> >>> > However, every Haskell implementation must support tuples up to size
>> >>> > 15, together with the instances for Eq, Ord, Bounded, Read, and Show.
>> >>>
>> >>> IMO, we either have no `Functor` instances for tuples at all, or we have
>> >>> them for all tuples up to size 15. The current situations of having them
>> >>> defined only for 2-tuples is inconsistent.
>> >>>
>> >>>
>> >>> Cheers,
>> >>> hvr
>> >>>
>> >>> [1]:
>> >>> https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1210006.1.4
>> >>> _______________________________________________
>> >>> Libraries mailing list
>> >>> Libraries at haskell.org
>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> >>
>> >>
>> >>
>> >>
>> >> --
>> >> Λ\ois
>> >> http://twitter.com/aloiscochard
>> >> http://github.com/aloiscochard
>> >>
>> >> _______________________________________________
>> >> Libraries mailing list
>> >> Libraries at haskell.org
>> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>> >
>> >
>> >
>> >
>> > --
>> > Λ\ois
>> > http://twitter.com/aloiscochard
>> > http://github.com/aloiscochard
>> >
>> >
>> > _______________________________________________
>> > 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
>
>
>
> --
> Chris Allen
> Currently working on http://haskellbook.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160119/f5a4f4fb/attachment.html>
More information about the Libraries
mailing list