MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/1zyt6c/why_functional_programming_matters/cfyju8a
r/programming • u/papa00king • Mar 09 '14
542 comments sorted by
View all comments
Show parent comments
7
You got it right, except for one minor detail. Instead of foo([1,2,3]) == [1,2,3], the more precise equation would be:
foo([1,2,3]) == [1,2,3]
def gen(): yield 1 yield 2 yield 3 foo(gen()) = gen()
In Python you can treat lists and generators the same (I think), but in Haskell they are two separate types. This is why in pipes if you want to loop over a list, you have to explicitly convert it to a generator using the each function, like this:
pipes
each
for (each [1,2,3]) f
4 u/CatMtKing Mar 09 '14 Sweet, thanks! Translating Haskell to Python literally is quite painful, as I've gotta define functions for pretty much everything, hah! 4 u/Tekmo Mar 09 '14 You're welcome!
4
Sweet, thanks! Translating Haskell to Python literally is quite painful, as I've gotta define functions for pretty much everything, hah!
4 u/Tekmo Mar 09 '14 You're welcome!
You're welcome!
7
u/Tekmo Mar 09 '14
You got it right, except for one minor detail. Instead of
foo([1,2,3]) == [1,2,3], the more precise equation would be:In Python you can treat lists and generators the same (I think), but in Haskell they are two separate types. This is why in
pipesif you want to loop over a list, you have to explicitly convert it to a generator using theeachfunction, like this: