4 ms·
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
by jhomedall 6y ago
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']
- Raidion 6y agoAs someone who does not program in functional languages, this really really helps clear up the article and surrounding discussion. Good stuff!
- dllthomas 6y agoOn the other hand, as someone with a bit of Haskell background, this doesn't even seem weird (except the use of String over Text).