Proposal: Add conspicuously missing Functor instances for tuples
ryan.gl.scott at gmail.com
Mon Jan 18 22:22:40 UTC 2016
> Is it important to achieve this with Bifunctor functions? You could write a state changing function, or add it to 'transformers', or define your own Writer as an independent type like it was in mtl initially.
For my use case, where I'm writing highly polymorphic code that needs
to be able to work over several datatypes with two type parameters,
using Bifunctor is quite less cumbersome than manually crafting
individual functions tailored to each individual data structure.
And while I certainly could define my own replacements for every
single tuple type, it feels a bit silly doing so when the perfect
datatypes are sitting right in front of me.
> Sure, but if you want a certain behaviour then a custom type is better than putting so much overloading to a standard (tuple) type, isn't it?
The phrase "custom behavior" is a bit confusing to me, since there's
literally only one law-abiding Functor and Traversable instance for
any tuple type (and the Foldable implementation falls out from that).
These instances aren't custom behavior, they're the only behavior they
can have in this context.
And I certainly don't view tuple instances as being "overloaded". IMO,
their instances are quite well though-out consequences of their
structure. When you're parametrically polymorphic in the last type
parameter of a tuple, the operations you can perform on it are what
the Functor and Traversable instances so nicely give you.
On Mon, Jan 18, 2016 at 5:10 PM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
> On Mon, 18 Jan 2016, Ryan Scott wrote:
>> WriterT (and Writer) don't quite capture what I need. With WriterT,
>> you have to tack on that extra m type parameter, and when you just
>> specialize it to Identity, it only serves as an extra hoop to jump
>> through to dig out the state. The prescence of the m type parameter
>> also prevents me from easily modifying the state with a Bifunctor
>> instance, whereas tuples have no such obstacle.
> Is it important to achieve this with Bifunctor functions? You could write a
> state changing function, or add it to 'transformers', or define your own
> Writer as an independent type like it was in mtl initially.
>> It's a minor difference, but an important one when I decide which data
>> structure to reach for.
> Sure, but if you want a certain behaviour then a custom type is better than
> putting so much overloading to a standard (tuple) type, isn't it?
More information about the Libraries