4 ms·
Think of an array such as int x[5][10]. Here x is a two dim. array. Indexing it just once such as x[i], you get another array, a vector of 10 ints, which can be
by bakul 9y ago
Think of an array such as int x[5][10]. Here x is a two dim. array. Indexing it just once such as x[i], you get another array, a vector of 10 ints, which can be indexed further. So in a sense x[i] is a "curried" array! In general given an N dim. array, indexing it K (less than N) times you get an array of N-K dimensions.
Now you can think of an array as a restricted function whose domain is 0..n x ... and range is some type. The same concept of "currying" applies to functions. That is, given a function of N arguments, if you provide K (less than N) arguments you get another function of N-K arguments.
It is strange that many programming languages allow currying of arrays but not of functions!
- megaman22 9y agoThis is also, imo, a terrible example. I've almost never seen a serious application of 2D arrays, unless they were weirdly sparse, that actually used the 2D array notation... Almost always, it's flattened into a memory-efficient representation as a 1D array, with a lookup expression to convert x, y coordinates into an index.
- bakul 9y agoThe point was to give the OP an example he can hopefully wrap his head around the concept of currying.