Proposal: Add conspicuously missing Functor instances for tuples

Andrew Butterfield Andrew.Butterfield at scss.tcd.ie
Tue Jan 19 15:46:26 UTC 2016


Of course, the proper/correct "implementation" for "Functor" with tuples should be 

instance Functor (,) where
  fmap (f,g) (a,b) = (f a, g b)

instance Functor (,,) where  
  fmap (f,g,h) (a,b) = (f a, g b, h c)

instance Functor (,,,) where
  fmap (f,g,h,k) (a,b) = (f a, g b, h c, k d)

and so on... (where fmap's type sig alters in a "tuple-structured" way with each instance...)

The current instance for (,)a  is my fmap(id, f)

Or should we have 15 classes ?

class Functor...
class BiFunctor...
class TriFunctor....
...
class QuincadecaFunctor /PentadecaFunctor - depending if you prefer Latin/Greek  ;-)

This probably doesn't clear anything up but does explain why heavy tuple use is deprecated
as per an earlier mail in this thread.....


Regards, Andrew



> On 19 Jan 2016, at 12:30, Carter Schonwald <carter.schonwald at gmail.com> wrote:
> 
> Agreed. +1
> 
> On Tuesday, January 19, 2016, Herbert Valerio Riedel <hvriedel at gmail.com <mailto: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 <https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1210006.1.4>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org <javascript:;>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries <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

Andrew Butterfield
School of Computer Science & Statistics
Trinity College
Dublin 2, Ireland

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160119/01710247/attachment-0001.html>


More information about the Libraries mailing list