<div dir="auto">This list is always topical for such feedback and design proposals (in fact generally all such base/boot lib changes should ideally be at least proposed here for visibility over time )</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 1, 2021 at 10:59 PM Viktor Dukhovni <<a href="mailto:ietf-dane@dukhovni.org">ietf-dane@dukhovni.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I hope it is acceptable on this list to solicit feedback on a<br>
documentation MR for the base library, specifically the Data.Traversable<br>
module:<br>
<br>
    <a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5873" rel="noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5873</a><br>
<br>
The rewrite touches a lot of text, and so most of you are likely to not<br>
find time for the full review that it perhaps deserves.  But I hope that<br>
one or two of you would be inclined to give it a go.<br>
<br>
In addition to the specifics of the exposition, both in Data.Traversable,<br>
and in Data.Foldable I'm opting for a somewhat new layout of the module<br>
documentation, with just a brief blurb at the top, then all the function<br>
synopses, and only after all that the detailed prose and laws, which<br>
were historically at the top of each module's documentation.<br>
<br>
I think the "prose last" format is more suitable for the typical user<br>
who wants to quickly glance at the documentation of a single function,<br>
or see what functions are in the module.  The detailed exposition is for<br>
those who want to take the time to be introduced to the relevant<br>
concepts.<br>
<br>
Section headings and links make it possible to navigate to the overview<br>
if one is instead interested in the introductory prose.<br>
<br>
I hope this format is a step in the right direction, or if not, this is<br>
a good opportunity to correct the document structure.<br>
<br>
Lastly, a comment in the MR asks whether it would be a good idea<br>
to tweak the definitions of mapAccumL and mapAccumR to "amp up"<br>
the use of coercions in the hope of a performance payoff.  See<br>
proposed patch below...<br>
<br>
-- <br>
    Viktor.<br>
<br>
diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs<br>
index db7e548325..6871e411a0 100644<br>
--- a/libraries/base/Data/Traversable.hs<br>
+++ b/libraries/base/Data/Traversable.hs<br>
@@ -432,8 +432,10 @@ forM = flip mapM<br>
 -- >>> mapAccumL (\a b -> (a <> show b, a)) "0" [1..5]<br>
 -- ("012345",["0","01","012","0123","01234"])<br>
 --<br>
-mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)<br>
-mapAccumL f s t = runStateL (traverse (StateL . flip f) t) s<br>
+type TraverseL t s a b = (a -> StateL s b) -> t a -> StateL s (t b)<br>
+mapAccumL :: forall t s a b. Traversable t<br>
+          => (s -> a -> (s, b)) -> s -> t a -> (s, t b)<br>
+mapAccumL f s t = coerce (traverse :: TraverseL t s a b) (flip f) t s<br>
<br>
 -- |The 'mapAccumR' function behaves like a combination of 'fmap'<br>
 -- and 'Data.Foldable.foldr'; it applies a function to each element of a structure,<br>
@@ -450,8 +452,10 @@ mapAccumL f s t = runStateL (traverse (StateL . flip f) t) s<br>
 -- >>> mapAccumR (\a b -> (a <> show b, a)) "0" [1..5]<br>
 -- ("054321",["05432","0543","054","05","0"])<br>
 --<br>
-mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)<br>
-mapAccumR f s t = runStateR (traverse (StateR . flip f) t) s<br>
+type TraverseR t s a b = (a -> StateR s b) -> t a -> StateR s (t b)<br>
+mapAccumR :: forall t s a b. Traversable t<br>
+          => (s -> a -> (s, b)) -> s -> t a -> (s, t b)<br>
+mapAccumR f s t = coerce (traverse :: TraverseR t s a b) (flip f) t s<br>
<br>
 -- | This function may be used as a value for `fmap` in a `Functor`<br>
 --   instance, provided that 'traverse' is defined. (Using<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div></div>