3 ms·
Which reminds me of an insightful observation that the array indexing operator [] and the function call operator () are basically doing the same thing: evaluati
by jiggawatts 6y ago
Which reminds me of an insightful observation that the array indexing operator [] and the function call operator () are basically doing the same thing: evaluating a function and returning a value.
So what you've just described is basically Currying, or partial function evaluation. It's a bit like defining "al(i)" as array lookup for an index 'i' instead of "[i]". Then the following are equivalent:
something[i][j]
something.al(i).al(j)
What people also want are:
something[i,j]
something.al(i,j)
In languages like Haskell, every function can always be evaluated argument-by-argument, with no special effort by the programmer. The compiler takes care of generating the code for the various intermediate call forms. In languages like C++, it would be a significant hassle to create all of the various partially-evaluated wrapper types.
- deleted 6y ago[deleted]
- gpderetta 6y agoIn C++ you can create a simple generic reusable currying wrapper. Boost as a few. The reality is that the vast majority of C++ programmers don't see the need.
- Animats 6y agoTrying to do this this through Currying turns a simple 2D array access into a quite complicated operation. One that a compiler has to be really smart to turn into a gheap 2D array indexing operation again. This really matters in number-crunching code, where it seems that almost everything is about multiplying arrays.
- gpderetta 6y agoOf course it wouldn't make much sense to do it for indexing. I was discussing currying as a generally useful tool.