--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
Don't trust partial application of infix ops unless you know they are commutative. Write a lambda instead.
Kasey, you keep talking as if there were a mathematical, semantic concept of “left-associativity” (and the same for “right-associativity”). But there isn’t. Or can you give a definition?
A definition of the mathematical, semantic concept of “associativity” is: “An operator is associative if applying that operator to a and b (in that order) and then applying it to the result of that and c (in that order) evaluates to the same result as applying it to a and to the result of applying it to b and c (in those orders).” No corresponding concept of “left-associativity” exists.
Reaching for something like “left-associativity means that a op b op c should be read as (a op b) op c“ means that you are talking of a parsing convention, not a mathematical property of the operator.
And all that is relevant because you are trying to make an argument about the behavior of some function being “mathematically wrong”, and basing that on something like “because it does not respect left-associativity”, which is moot given that there is no semantic property that you could state and see violated.
Similarly, you make a statement about “current foldl does not fold from the left”, but haven’t defined semantically what it means to “fold from the left”. One such definition could be “folding from the left means that the left-most element is first combined with the second-left-most element before any other elements are used”. In that sense, current foldl is folding from the left. If you want to say that it is not, you have to provide an alternative definition of the concept of “folding from the left”. Can you? Can you tell us what it is?
Aside: About the concepts of associativity, you may want to compare https://en.wikipedia.org/wiki/Operator_associativity and https://en.wikipedia.org/wiki/Associative_property, and to consider the explicit pointer from the former to the latter as regards “the mathematical concept of associativity”, as well as taking note of the fact that the latter page does not mention anything like “left-associativity” and “right-associativity” (because, I repeat, those do not exist as mathematical, semantical-as-opposed-to-syntactical concepts).
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
[1,2,3,4,5] with the addition operator would result in 15, the sum of the elements of the list [1,2,3,4,5]. To a rough approximation, one can think of this fold as replacing the commas in the list with the + operation, giving 1 + 2 + 3 + 4 + 5."I do know how foldl is in other languages. And that it is different in those other languages than it is in Elm. And I even agree that it would be better that foldl in Elm is as in other languages (or Haskell, specifically). I think I even argued for this on this mailing list in the past.
But all this is not what my message to you was about. I pointed out that you have no argument for this position that is of the form “… because of mathematics”. All the argument you (or I) have is that other languages do something different and that it would be nicer if Elm behaved like those, also because what those do is easier to explain/visualize. You didn’t seem to acknowledge that this is the only argument you have, before. Your latest message suggests you now do see that this is the only argument you have. (It’s a fine argument. But it’s only this one, not a stronger mathematical argument as you previously tried to make exist.)
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
And I do get the mathematically wrong answer on foldl when using mathematically non-associative operations (like subtraction). That's provided we agree on the definition of which side of the list is the "left" side.
Well, still not quite for me. I’m sure we both agree what the “left” side of the list is. And still I don’t think there is an argument to make that hence Elm’ foldl‘s answer is mathematically wrong. The fact that we agree what the left side of the list is does not mean that foldl (-) 0 [1,2,3] needs to evaluate to ((0 - 1) - 2) -3. It can evaluate to 3 - (2 - (1 - 0)) without us disagreeing what is “left”. In other words, “leftiness” is not at issue here. Both ((0 - 1) - 2) -3 and 3 - (2 - (1 - 0)) do work “from the left”. They combine elements in the order in which they appear in the list from left to right. One could argue that the real thing at issue here is not what “left” means, but what “folding” means. You take it to mean to literally replace :: by (-) and you are only willing to argue about how the result is bracketed. But one can take “folding” to simply mean that stuff gets accumulated via an operator, and “left folding” then means that more-left-sitting elements get accumulated earlier. And Elm’s foldl is perfectly mathematically correct according to this meaning.
Of course, that’s back to a point I made already the other day. There’s nothing “mathematically wrong” about Elm’s foldl unless one postulates “mathematically correct” to mean “ foldl needs to be the specific operation it is in Haskell etc.” But that’s not a mathematical argument.
I would like to point out that: I’m sure neither of us is too stupid to know what the other means. :-)
And I don’t think there is no basis to discuss these aspects. In fact, here is a possible explanation of why this all seems so fuzzy: One could distinguish between “from left to right in terms of the input” and “from left to right in the output”. Then:
((0 - 1) - 2) - 3 processes elements from left to right in terms of the input and happens to produce an expression that is nested from left to right in the output3 - (2 - (1 - 0)) processes elements from left to right in terms of the input and happens to produce an expression that is nested from right to left in the outputThe distinction you make between “head to tail” and “left to right” (as if you would be fine with the current Elm behavior of foldl aka foldLeftToRight if it were simply called foldHeadToTail instead) is not one I can relate to.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
The two examples you provide, the first is left-to-right on both input and output. The other (Elm's) is not. Right fold is right-to-left on both input and output. The lack of symmetry between the two operations only reinforces the issue.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
Having the behavior you expect? So if you write List.foldl (++) "" ["a", "b", "c"], you expect to get "cba"?