Proposal: Add conspicuously missing Functor instances for tuples

Andreas Abel abela at chalmers.se
Tue Jan 19 07:41:25 UTC 2016


-1 from me.

First, I think people should be discouraged from using tuples.  Tuples 
for anything but very short-lived structures (like returning multiple 
results from a function) make code very unmaintainable.  Instead 
hand-rolled records are the tool of choice, for which you can define 
your functor instance as you see fit.

Second, it is confusing that

   fmap (+1) (1,2,3) = (1,2,4)

while

   fmap (+1) [1,2,3] = [2,3,4]

--Andreas

On 18.01.2016 21:10, 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.
>
> I would really love to see these make 8.0.0, but if that's impossible
> then so be it.
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


-- 
Andreas Abel  <><      Du bist der geliebte Mensch.

Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden

andreas.abel at gu.se
http://www2.tcs.ifi.lmu.de/~abel/


More information about the Libraries mailing list