Re:Do notation considered harmful
by tome on Wednesday April 29, 2020 @09:34AM
(#23018890)
An example would be probably make your case stronger.
[ Parent
| on HN ]
This:
do
x <- ["a","b","c"]
y <- ["d","e","f"]
return (x ++ y)
evaluates to: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Note that this is _not_ equivalent to: ["a", "b", "c"] ++ ["d", "e", "f"]
which would instead evaluate to ["a","b","c","d","e","f"]
The Python equivalent would be: [(a + b) for a in ["a", "b", "c"] for b in ["d", "e", "f"]]
Which evaluates to: ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']As someone who does not program in functional languages, this really really helps clear up the article and surrounding discussion. Good stuff!