6 ms·
It is not about distaste, though idea about keeping and carrying 1 around is a recipe for bugs. It is all about composability. Could you make proper monoid out
by Iwan-Zotow 8y ago
It is not about distaste, though idea about keeping and carrying 1 around is a recipe for bugs. It is all about composability.
Could you make proper monoid out of Julia ranges? What would be a unit in that monoid? Could you tell me how empty range looks in Julia (in Python/C++ it looks trivial)?
> Python cannot even index lists by ranges (or other lists)
sure, Python has deficiencies as well.
C++ STL iterators/ranges are made in the same way, and for a good reason - composability first. It described very well in Alex Stepanov book (https://www.amazon.com/Mathematics-Generic-Programming-Alexander-Stepanov/dp/0321942043/ref=sr_1_1?ie=UTF8&qid=1548359366&sr=8-1&keywords=stepanov+generic+programming https://www.amazon.com/Mathematics-Generic-Programming-Alexa...), as well as how it helps when we move to parallel algorithms (http://stepanovpapers.com/p5-austern.pdf http://stepanovpapers.com/p5-austern.pdf).
It is even more explicit in upcoming Ranges library in C++20
- 3JPLW 8y agoAn empty range in Julia is `1:0`. So yes, they can form monoids just fine. I highly recommend you work with them _directly_ instead of carrying around the two endpoints separately. For example, you can divide any range into two parts with: split(r) = r[1:end÷2], r[end÷2+1:end] That'll happily recurse and eventually spit out empty ranges given an input like `split(32:56)`. A zealous adherence to one strategy or another will simply blind you to the ways in which the other might be easier at different times.