<div dir="ltr">An alternate question might be, why is <font face="monospace, monospace">length</font> a class member and not simply a function? The instance itself is merely documentation of a mathematical fact; it's only a few members of that instance (which are never part of its minimum definition!) that seem confusing.<div><br></div><div>I'm sure the answer to that involves optimizations available for particular structures, case in point for tuples:<div><br></div><div><span style="font-family:monospace,monospace">length = const 1</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div>But it's worth understanding it in detail, probably.</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 3, 2017 at 1:51 AM, Chris Smith <span dir="ltr"><<a href="mailto:cdsmith@gmail.com" target="_blank">cdsmith@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Replying to myself, I suppose one good answer is that whether or not you care about Foldable instances for tuples, you might care about Traversable instances, and those require Foldable as a superclass.<div><br></div><div>For example, one possible specialization of `traverse` is:</div><div><br></div><div> traverse :: (a -> IO b) -> (SideValue, a) -> IO (SideValue, b)</div><div><br></div><div>Jonathon, I don't know how much background you're coming from, so I'd be happy to explain that in more detail if you need it.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 3, 2017 at 1:44 AM, Chris Smith <span dir="ltr"><<a href="mailto:cdsmith@gmail.com" target="_blank">cdsmith@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm also interested in Jonathon's question, so let me try to bring things back to the question. Everyone agrees that there's only one reasonable way to define this instance if it exists. But the question is: why is it defined at all?<div><br></div><div>That's an easy question to answer for Functor, Applicative, and Monad. But I am having trouble giving a simple or accessible answer for Foldable. Do you know one?</div></div><div class="m_-1008651892188650676HOEnZb"><div class="m_-1008651892188650676h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 3, 2017 at 1:32 AM, Tony Morris <span dir="ltr"><<a href="mailto:tonymorris@gmail.com" target="_blank">tonymorris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It's Foldable for ((,) a).<br>
<br>
It is not Foldable for any of these things:<br>
<br>
* (,)<br>
* tuples<br>
* pairs<br>
<br>
In fact, to talk about a Foldable for (,) or "tuples" is itself a kind<br>
error. There is no good English name for the type constructor ((,) a)<br>
which I suspect, along with being unfamiliar with utilising the<br>
practical purpose of types (and types of types) is the root cause of all<br>
the confusion in this discussion.<br>
<br>
Ask yourself what the length of this value is:<br>
<br>
[[1,2,3], [4,5,6]]<br>
<br>
Is it 6? What about this one:<br>
<br>
[(1, 'a'), (undefined, 77)]<br>
<br>
Is it 4? No, obviously not, which we can determine by:<br>
<br>
:kind Foldable :: (* -> *) -> Constraint<br>
:kind [] :: * -> *<br>
<br>
Therefore, there is no possible way that the Foldable instance for []<br>
can inspect the elements (and determine that they are pairs in this<br>
case). By this method, we conclude that the length of the value is 2. It<br>
cannot be anything else, some assumptions about length itself put aside.<br>
<br>
By this ubiquitous and very practical method of reasoning, the length of<br>
any ((,) a) is not only one, but very obviously so.<br>
<div class="m_-1008651892188650676m_6611944479389780505HOEnZb"><div class="m_-1008651892188650676m_6611944479389780505h5"><br>
On 03/05/17 17:21, Jonathon Delgado wrote:<br>
> I sent the following post to the Beginners list a couple of weeks ago (which failed to furnish an actual concrete example that answered the question). Upon request I'm reposting it to Café:<br>
><br>
> I've seen many threads, including the one going on now, about why we need to have:<br>
><br>
> length (2,3) = 1<br>
> product (2,3) = 3<br>
> sum (2,3) = 3<br>
> or (True,False) = False<br>
><br>
> but the justifications all go over my head. Is there a beginner-friendly explanation for why such seemingly unintuitive operations should be allowed by default?<br>
> ______________________________<wbr>_________________<br>
> Haskell-Cafe mailing list<br>
> To (un)subscribe, modify options or view archives go to:<br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
> Only members subscribed via the mailman list are allowed to post.<br>
<br>
<br>
</div></div><br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>