Proposal: Add conspicuously missing Functor instances for tuples

David Feuer david.feuer at gmail.com
Mon Jan 18 20:37:38 UTC 2016


Actually, I currently get a much worse error message:

Prelude> fmap (+1) (1,2,3)

<interactive>:2:1:
    Non type-variable argument in the constraint: Functor ((,,) t t)
    (Use FlexibleContexts to permit this)
    When checking that ‘it’ has the inferred type
      it :: forall b t t1.
            (Functor ((,,) t t1), Num b, Num t, Num t1) =>
            (t, t1, b)

That there is a *lousy* error message.

I understand that there are newcomers who struggle to understand the
difference between tuples and lists; I don't think that's a good
enough reason to omit a good and valid instance.

On Mon, Jan 18, 2016 at 3:32 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Mon, 18 Jan 2016, David Feuer wrote:
>
>> I'd be strongly +1 on that too! Traversable is strong magic.
>
>
> I am opposed to all these Functor, Foldable, Traversable stuff on tuples
> (including pairs). Why should the last element of a tuple get a special
> treatment? I suspect that if you use such instances you are making something
> dirty. I am afraid that those instance may hide type errors or make type
> errors incomprehensible. E.g. if you get a stack of fmap's wrong, you do not
> get a "no instance for Functor ((,) a)" but instead the type mismatch occurs
> at a different level.
>
> I would never use such an instance. Can I be warned if I accidentally use it
> anyway?


More information about the Libraries mailing list