|
|
|
|
|
by sesuximo
2011 days ago
|
|
Imo foo[x][y] is better for many reasons: - compiler can break it apart so foo[x] is evaluated once for many ys just like any other function - you can make types that are unaware of their rank eg vector doesn’t know if it’s a 1D vector of int or a 2D vector of vectors - “seamlessly” handles jagged arrays |
|
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:
What people also want are: 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.