3 ms·
More subtly, a generator (or list comprehension) implies the order in which the results are generated and an implicit but observable changing state. If I'm tryi
by Locke1689 13y ago
More subtly, a generator (or list comprehension) implies the order in which the results are generated and an implicit but observable changing state. If I'm trying to write (or, at least, express, since we are talking about Python) parallelism, map would be a better choice.
This is definitely not true -- generator expressions can be expressed using lazy list semantics. By your logic every Haskell list comprehension would be stateful.
I would encourage you to write the denotational or operational semantics of your expressions in these matters rather than simply going by intuition.
- rbanffy 13y ago> generator expressions can be expressed using lazy list semantics That does not change the fact the results are given in a certain order. Lazy list semantics means the data will be calculated as it's needed, therefore, the calculation cannot be parallelized.
- Locke1689 13y agoNot true. See http://hackage.haskell.org/packages/archive/parallel/3.1.0.1/doc/html/Control-Parallel-Strategies.html#v:parList http://hackage.haskell.org/packages/archive/parallel/3.1.0.1...
- rbanffy 13y agoI was talking about Python. A list comprehension is defined as having the behavior of a loop.
- Locke1689 13y agoOnce again, that doesn't semantically make a difference, unless the loop is side-effecting. However, even without side effects, Python cannot necessarily make any kind of guarantee about such computations since arrays are mutable and can be modified out from under the map. This is why parmap equivalents take iterables in Python, not arrays. It doesn't matter if you have lazy or eager semantics, only if your semantics are side-effecting.