
10 Nov
2008
10 Nov
'08
1:48 p.m.
Jonathan Cast wrote:
On Mon, 2008-11-10 at 18:20 +0000, Andrew Coppin wrote:
Mitchell, Neil wrote:
In general:
if boolean then [value] else []
Can be written as:
[value | boolean]
Is there any specific reason why this is valid?
Is there any specific reason to dis-allow it? The grammar here looks something like (NB: I didn't double-check the report):
list_compr ::= [ value | generator* ] generator ::= boolean | pat <- list | let binds
Hmm, that's interesting. I didn't know that a Boolean was a valid generator. (Presumably this has the effect of filtering?) The only time I use list comprehensions is when I quickly want a Cartesian product. I wasn't really aware it could filter as well.