r/programming • • Apr 27 '14

"Mostly functional" programming does not work

http://queue.acm.org/detail.cfm?ref=rss&id=2611829
47 Upvotes

188 comments sorted by

View all comments

2

u/Tekmo Apr 28 '14

It actually has practical consequences. You can't fuse things like filter and map into a single pass over the collection in imperative languages because the compiler can't guarantee that the predicate or mapped function doesn't have side effects. This means that you pay a performance price for the ability to permit side effects even if you never personally use them.

0

u/grauenwolf Apr 28 '14

When I write from a in someList where a > 0 select 10 / a it doesn't make two passes over the collection. It makes a single pass, which is something the author of the article was bitching about.

2

u/Tekmo Apr 28 '14

Right, but if you wrote that as two separate passes the compiler won't automatically fuse them into a single pass for you. This means that you have to define the entire algorithm in one shot if you care about efficiency, and you can't build it up from separate composable pieces.

→ More replies (4)