Category talk:Iteration: Difference between revisions

Explain why list iteration is not just Map
(→‎OpenMP looping?: new section)
(Explain why list iteration is not just Map)
Line 3:
: Loop/Map is already there, as [[Apply a callback to an Array]] (see the Common Lisp solution!) I don't know what Loop/Fold means, but maybe it's also already there under another name. --[[User:Ce|Ce]] 13:28, 18 April 2008 (MDT)
::The articles [[Sum and product of array]] contains some examples of '''Fold'''(or reduce). '''Fold''' apply a binary function(ZxZ->Z) to each elements of a collection with an accumulator, the result value is set to the accumulator, and the final value of accumulator after iterated all elements is the result of '''Fold''' (the accumulator initialized to 1.0 in Product case, and 0.0 in Sum case). '''Map''' is similar, but with an unary function Z->Z. There is also '''Filter/Select'''(compare [[Select from Array]]) similar to '''Map''', with an unary boolean function, but don't keep elements if result value is false. -- [[User:Badmadevil|badmadevil]] 05:58, 19 April 2008 (MDT)
:: FWIW, [[Apply a callback to an Array]] isn't Loop/Map because there's no requirement to reassemble the values into another array (or sequence/list, etc.) In [[SML]]-like type-theoretic terms, Map is
::: <math>(\alpha \rightarrow \beta) \rightarrow \alpha\, \mathrm{list} \rightarrow \beta\, \mathrm{list}</math>
:: whereas that task allows
::: <math>(\alpha \rightarrow \mathrm{unit}) \rightarrow \alpha \, \mathrm{list} \rightarrow \mathrm{unit}</math>
:: These are quite different type signatures, though Map can be used for the other by throwing away the final result. –[[User:Dkf|Donal Fellows]] 12:40, 4 January 2010 (UTC)
 
What about "implied loops" like the one Fortran can use to initialize arrays or in the where construct? (Maybe implied is not correct... but the final operation in other languages like C is a ''for'' loop, but in these languages it is not written explicitly); e.g.
Anonymous user