<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">To me, the fact that DeriveTraversable requires a Foldable instance is not an argument saying that Foldable needs to be a superclass of Traversable. It just restricts the usefulness of DeriveTraversable. We could always advertise that DeriveTraversable works only on types with Foldable instances -- no need to bake this restriction into the superclass constraints of Traversable.</div><div class=""><br class=""></div><div class="">To be clear, I'm *not* arguing that Foldable shouldn't be a superclass of Traversable. I'm not knowledgeable enough on the specifics to make that claim. I *am* arguing that support for DeriveTraversable doesn't seem to a great argument for putting Foldable as a superclass of Traversable, though.</div><div class=""><br class=""></div><div class="">Richard</div><br class=""><div><blockquote type="cite" class=""><div class="">On May 3, 2017, at 10:38 AM, Dmitry Olshansky <<a href="mailto:olshanskydr@gmail.com" class="">olshanskydr@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Traversable instances (for "singletons" or not) can be implemented _uniformly_ using Functor and Foldable instances.<br class=""></div>And they are implemented in such way when you derive Traversable. So we need Foldable constraint for the class.<br class=""><br class=""></div>E.g.<br class=""></div>{-# LANGUAGE DeriveFunctor, DeriveFoldable,DeriveTraversable #-}<br class=""></div>> data D a = D { f1 :: [a], f2 :: (String, a) } deriving (Show, Eq, Functor, Foldable, Traversable)<br class=""><div class=""><div class=""><div class=""><div class="">> sum $ D [1..3] ("test",4)<br class="">10<br class="">> mapM_ print $ sequenceA $ D [[1,2],[3,4]] ("test",[5,6])<br class="">D {f1 = [1,3], f2 = ("test",5)}<br class="">D {f1 = [1,3], f2 = ("test",6)}<br class="">D {f1 = [1,4], f2 = ("test",5)}<br class="">D {f1 = [1,4], f2 = ("test",6)}<br class="">D {f1 = [2,3], f2 = ("test",5)}<br class="">D {f1 = [2,3], f2 = ("test",6)}<br class="">D {f1 = [2,4], f2 = ("test",5)}<br class="">D {f1 = [2,4], f2 = ("test",6)}<br class=""><br class=""></div><div class=""><br class=""></div></div></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2017-05-03 14:34 GMT+03:00 Jonathon Delgado <span dir="ltr" class=""><<a href="mailto:voldermort@hotmail.com" target="_blank" class="">voldermort@hotmail.com</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Interesting, that's not the one linked to from Dmitry's code.<br class="">
<br class="">
In any case, is this correct?<br class="">
<br class="">
1) Traversable is useful for all containers, including ones which can only hold a single value, such as (,) a.<br class="">
2) The traversable definition for containers which can hold multiple versions requires Foldable.<br class="">
3) So Traversable has to depend on Foldable.<br class="">
4) So singleton containers also have to implement Foldable, even when it doesn't really make sense to do so.<br class="">
<br class="">
Is there some kind of refactoring which would "fix" this, other than two unrelated Traversable classes? I understand that it might be impractical to refactor a widely-used standard library, but I would be interested in how such a situation could be avoided when starting from scratch.<br class="">
<span class=""><br class="">
<br class="">
<br class="">
From: Haskell-Cafe <<a href="mailto:haskell-cafe-bounces@haskell.org" class="">haskell-cafe-bounces@haskell.<wbr class="">org</a>> on behalf of Tony Morris <<a href="mailto:tonymorris@gmail.com" class="">tonymorris@gmail.com</a>><br class="">
</span>Sent: 03 May 2017 11:21<br class="">
To: <a href="mailto:haskell-cafe@haskell.org" class="">haskell-cafe@haskell.org</a><br class="">
<div class=""><div class="h5">Subject: Re: [Haskell-cafe] Foldable for (,)<br class="">
 <br class="">
<a href="https://i.imgur.com/A2enuhq.png" rel="noreferrer" target="_blank" class="">https://i.imgur.com/A2enuhq.<wbr class="">png</a><br class="">
<br class="">
<br class="">
On 03/05/17 21:17, Jonathon Delgado wrote:<br class="">
> List.foldr has signature (a -> b -> b) -> b -> [a] -> b, i.e. an actual list? How is this effected by the Foldable constraint?<br class="">
><br class="">
><br class="">
><br class="">
> From: Dmitry Olshansky <<a href="mailto:olshanskydr@gmail.com" class="">olshanskydr@gmail.com</a>><br class="">
> Sent: 03 May 2017 10:47<br class="">
> To: Jonathon Delgado<br class="">
> Cc: <a href="mailto:haskell-cafe@haskell.org" class="">haskell-cafe@haskell.org</a><br class="">
> Subject: Re: [Haskell-cafe] Foldable for (,)<br class="">
>  <br class="">
><br class="">
><br class="">
> Look how instance for List is defined.<br class="">
><br class="">
> instance Traversable [] where     {-# INLINE traverse #-} -- so that traverse can fuse     traverse f = List.foldr cons_f (pure [])       where cons_f x ys = (:) <$> f x <*> ys It uses List.foldr. Many other instances do the same.<br class="">
> Functions in all instances of class should have the same signatures. So we have to add Foldable constraint to the class.<br class="">
> Of cause we can implement 'foldr' internaly in 'traverse' if needed (as well as fmap).<br class="">
> But this is not so good and more important that in this case we don't know how to derive Traversable instances automatically.<br class="">
><br class="">
> So the answer - many instances wouldn't compile and DeriveTraversable wouldn't work.<br class="">
>  <br class="">
><br class="">
><br class="">
> 2017-05-03 12:56 GMT+03:00 Jonathon Delgado  <<a href="mailto:voldermort@hotmail.com" class="">voldermort@hotmail.com</a>>:<br class="">
>  OK, I understand why Traversable is useful here - thank you Chris and Dmitry!<br class="">
><br class="">
> The next question is why Traversable requires Foldable. I looked at the source, and couldn't see where Foldable is being used, other than as a constraint on Traversable. To put the question differently, what would fail to compile if this constraint was removed?<br class="">
><br class="">
><br class="">
><br class="">
> From: Dmitry Olshansky <<a href="mailto:olshanskydr@gmail.com" class="">olshanskydr@gmail.com</a>><br class="">
> Sent: 03 May 2017 09:53<br class="">
> To: Jonathon Delgado<br class="">
><br class="">
><br class="">
> Cc: <a href="mailto:haskell-cafe@haskell.org" class="">haskell-cafe@haskell.org</a><br class="">
> Subject: Re: [Haskell-cafe] Foldable for (,)<br class="">
> <br class="">
><br class="">
><br class="">
><br class="">
><br class="">
> With fmap you can only change all values in some "container".<br class="">
><br class="">
>  With Foldable you can "fold" it, i.e. calculate some "scalar" result.<br class="">
><br class="">
>  With Traversable you can "change order of two containers":<br class="">
>> sequenceA [[1,2,3],[4,5]]<br class="">
> [[1,4],[1,5],[2,4],[2,5],[3,4]<wbr class="">,[3,5]]<br class="">
>> sequenceA ("test",[2,3,4])<br class="">
> [("test",2),("test",3),("test"<wbr class="">,4)]<br class="">
>> sequenceA ("test",([1,2,3],[4,5,6]))<br class="">
> ([1,2,3],("test",[4,5,6]))<br class="">
><br class="">
><br class="">
><br class="">
><br class="">
><br class="">
> 2017-05-03 12:12 GMT+03:00 Jonathon Delgado  <<a href="mailto:voldermort@hotmail.com" class="">voldermort@hotmail.com</a>>:<br class="">
>  Why do you want to traverse a tuple instead of fmap? i.e. what can you do with Foldable/Traversable for (,) that you can't do with Functor?<br class="">
><br class="">
> My background, as you can probably guess, is beginner.<br class="">
><br class="">
><br class="">
> From: Haskell-Cafe <<a href="mailto:haskell-cafe-bounces@haskell.org" class="">haskell-cafe-bounces@haskell.<wbr class="">org</a>> on behalf of Chris Smith <<a href="mailto:cdsmith@gmail.com" class="">cdsmith@gmail.com</a>><br class="">
> Sent: 03 May 2017 08:51<br class="">
> To: Tony Morris<br class="">
> Cc: <a href="mailto:haskell-cafe@haskell.org" class="">haskell-cafe@haskell.org</a><br class="">
> Subject: Re: [Haskell-cafe] Foldable for (,)<br class="">
> <br class="">
><br class="">
><br class="">
><br class="">
> 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.<br class="">
><br class="">
><br class="">
> For example, one possible specialization of `traverse` is:<br class="">
><br class="">
><br class="">
>     traverse :: (a -> IO b) -> (SideValue, a) -> IO (SideValue, b)<br class="">
><br class="">
><br class="">
> 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.<br class="">
><br class="">
><br class="">
> On Wed, May 3, 2017 at 1:44 AM, Chris Smith  <<a href="mailto:cdsmith@gmail.com" class="">cdsmith@gmail.com</a>> wrote:<br class="">
><br class="">
> 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?<br class="">
><br class="">
><br class="">
> 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?<br class="">
><br class="">
><br class="">
><br class="">
><br class="">
> On Wed, May 3, 2017 at 1:32 AM, Tony Morris  <<a href="mailto:tonymorris@gmail.com" class="">tonymorris@gmail.com</a>> wrote:<br class="">
>  It's Foldable for ((,) a).<br class="">
><br class="">
> It is not Foldable for any of these things:<br class="">
><br class="">
> * (,)<br class="">
> * tuples<br class="">
> * pairs<br class="">
><br class="">
> In fact, to talk about a Foldable for (,) or "tuples" is itself a kind<br class="">
> error. There is no good English name for the type constructor ((,) a)<br class="">
> which I suspect, along with being unfamiliar with utilising the<br class="">
> practical purpose of types (and types of types) is the root cause of all<br class="">
> the confusion in this discussion.<br class="">
><br class="">
> Ask yourself what the length of this value is:<br class="">
><br class="">
> [[1,2,3], [4,5,6]]<br class="">
><br class="">
> Is it 6? What about this one:<br class="">
><br class="">
> [(1, 'a'), (undefined, 77)]<br class="">
><br class="">
> Is it 4? No, obviously not, which we can determine by:<br class="">
><br class="">
> :kind Foldable :: (* -> *) -> Constraint<br class="">
> :kind [] :: * -> *<br class="">
><br class="">
> Therefore, there is no possible way that the Foldable instance for []<br class="">
> can inspect the elements (and determine that they are pairs in this<br class="">
> case). By this method, we conclude that the length of the value is 2. It<br class="">
> cannot be anything else, some assumptions about length itself put aside.<br class="">
><br class="">
> By this ubiquitous and very practical method of reasoning, the length of<br class="">
> any ((,) a) is not only one, but very obviously so.<br class="">
><br class="">
><br class="">
><br class="">
> On 03/05/17 17:21, Jonathon Delgado wrote:<br class="">
>> 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 class="">
>><br class="">
>> I've seen many threads, including the one going on now, about why we need to have:<br class="">
>><br class="">
>> length (2,3) = 1<br class="">
>> product (2,3) = 3<br class="">
>> sum (2,3) = 3<br class="">
>> or (True,False) = False<br class="">
>><br class="">
>> 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 class="">
>> ______________________________<wbr class="">_________________<br class="">
>> Haskell-Cafe mailing list<br class="">
>> To (un)subscribe, modify options or view archives go to:<br class="">
>>     <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
<br class="">
<br class="">
</div></div><span class="">Haskell-Cafe Info Page<br class="">
<a href="http://mail.haskell.org/" rel="noreferrer" target="_blank" class="">mail.haskell.org</a><br class="">
This mailing list is for the discussion of topics related to Haskell. The volume may at times be high, as the scope is broader than the main Haskell mailing list.<br class="">
<br class="">
</span><span class="">>> Only members subscribed via the mailman list are allowed to post.<br class="">
><br class="">
><br class="">
> ______________________________<wbr class="">_________________<br class="">
> Haskell-Cafe mailing list<br class="">
> To (un)subscribe, modify options or view archives go to:<br class="">
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
<br class="">
<br class="">
</span><span class="">Haskell-Cafe Info Page<br class="">
<a href="http://mail.haskell.org/" rel="noreferrer" target="_blank" class="">mail.haskell.org</a><br class="">
This mailing list is for the discussion of topics related to Haskell. The volume may at times be high, as the scope is broader than the main Haskell mailing list.<br class="">
<br class="">
</span><span class="">> Only members subscribed via the mailman list are allowed to post.<br class="">
><br class="">
><br class="">
><br class="">
> ______________________________<wbr class="">_________________<br class="">
> Haskell-Cafe mailing list<br class="">
> To (un)subscribe, modify options or view archives go to:<br class="">
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
> Only members subscribed via the mailman list are allowed to post.<br class="">
><br class="">
> ______________________________<wbr class="">_________________<br class="">
> Haskell-Cafe mailing list<br class="">
> To (un)subscribe, modify options or view archives go to:<br class="">
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
> Only members subscribed via the mailman list are allowed to post.  <br class="">
>    <br class="">
> ______________________________<wbr class="">_________________<br class="">
> Haskell-Cafe mailing list<br class="">
> To (un)subscribe, modify options or view archives go to:<br class="">
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
> Only members subscribed via the mailman list are allowed to post.<br class="">
<br class="">
<br class="">
</span><a href="https://i.imgur.com/A2enuhq.png" rel="noreferrer" target="_blank" class="">https://i.imgur.com/A2enuhq.<wbr class="">png</a><br class="">
<div class="HOEnZb"><div class="h5"><br class="">
______________________________<wbr class="">_________________<br class="">
Haskell-Cafe mailing list<br class="">
To (un)subscribe, modify options or view archives go to:<br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
Only members subscribed via the mailman list are allowed to post.</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.</div></blockquote></div><br class=""></body></html>