-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order of iteration #29
Comments
@mikeshulman This is a very good point and I must admit that I didn't think through this issue very carefully. The only (very weak) counterargument I could think of is that we should not change the subtle behaviors of an API. However, this could be solved by a major version jump. |
I wasn't necessarily suggesting to change it, just wanted to understand the intent. But I certainly wouldn't object if you change it. |
@mikeshulman The original intent, I believe, was to signify that the lists are from the "right," and engineering-wise we sometimes can have tail-recursive code by following the order of elements in the underlying data structure. However, this is arguably violating the principle of "cherishing the text order." Anyway I don't feel I have thought through this carefully. |
Yes, I see the tail-recursion point for traversing right-to-left. In principle one could include both and let the user choose as appropriate; then the only question would be how to name them. |
Textual vs. temporal? Spatial vs. temporal? |
I was thinking of |
@mikeshulman @jonsterling Idea: just like |
@favonia My only critique is: these names are very hard on my 🧠 because "folding from the left" and "folding to the left" are equally likely interpretations to me. (This is one of the reasons I can never remember which of |
I like @jonsterling's idea (in a private channel) to highlight the difference conceptually. It's not about left v.s. right, but the textual order v.s. the underlying/physical/induction order. If we follow this approach, we can also define these for the built-in OCaml lists, just that they would agree. We can make one of them the default in |
The alternative approach, which is what @mikeshulman mentioned, is to take textual as the definition, and thus "backward" means the opposite of textual. |
Regardless of the approach we want to take, I propose the following migration plan:
|
@mikeshulman Hmm I'm checking the documentation of |
You're right that the documentation of
In fact, I think this documentation is positively confusing, because in practice
My bug was because I assumed that |
For a name, I actually kind of like |
By the way, I recently also had reason to want a version of |
I am also looking at related functions including |
Amusingly, I realized recently that if one defines a version of (Supposedly one can implement the reverse state monad in OCaml using Lazy, but I wasn't able to get it to work. However, it's quite easy to implement reverse state as an applicative functor, which is good enough for this.) Of course this is kind of overkill for mapping over lists, especially given how in OCaml you have to use the heavy module syntax for parametrizing something over a monad or applicative. But I've found it useful to avoid writing multiple traversal functions for more complicated data structures. |
Thanks for the reminder that this issue has not been resolved yet... |
@jonsterling @mikeshulman We seem to have this consensus:
The main disagreement is what suffixes (or prefixes?) to use. Here are some proposals (including the secret ones I was trying out):
Some technical details to sort out:
Here are the full table after 3.0.0, using
|
Isn't calling left-to-right "textual" a bit parochial? (-: People who read right-to-left might call that order "textual". Actually one could even make the same point about "forwards". |
@mikeshulman I thought about it and felt it might be fine; in the areas where right-to-left text is prevailing, the list will probably be written from right to left as well. Therefore, "textual" and "forward/backward" will remain consistent. The problematic ones are "left" and "right". |
Oh, interesting. I guess I could live with forward/backward then, although I still think I prefer left and right, to match the existing names of folds. It would be nice to survey a slightly larger number of functional programmers than we have here, to see what they would find more intuitive. |
I think part of my hesitation about "forward/backward" is that if "forwards" means left-to-right and "backwards" means right-to-left (at least for those of us who read left-to-right), then it seems that a |
Just to throw another option out there, we could have |
Forwards/backwards really confuses me so very deeply, for much the reasons @mikeshulman is mentioning... One could really draw almost any conclusion from the naming... I think I really like |
Another possibility is to use temporal intuitions to avoid confusion — "fifo" vs "lifo". |
@jonsterling Oh, that's why you mentioned temporal v.s. spatial---I finally had some ideas. I'm not sure how they apply to functions such as |
I presume that |
I am curious why the decision was made for
Bwd.map
,Bwd.iter
, and so on to operate from right to left rather than from left to right. This is counterintuitive to me (and has led to at least one bug in my code so far). To me, the order in which the elements of a list are visited goes naturally with the textual order, since we read (in English) from left to right.Moreover, I feel like in practice one of the reasons I care about having things in an order at all is so that I can iterate over them in that order, and the order in which I want to maintain things may be independent from which end of the order I most frequently want to add and remove elements from. In fact I might argue that for adding things, at least, the more common situation is to want to add things at the "end" of the order in which I want to iterate over them.
The text was updated successfully, but these errors were encountered: