News for hackers. Stuff that matters.
Re:Why functional programming? by MichaelGG on Tuesday December 24, 2013 @03:03PM (#6960914)
Something like "map myints (+ 1)" can be performed in a mutable way, without compromising on functional purity. (So long you're not using the old values afterwards, of course.)

Not all compilers perform such optimizations, but there's no fundamental conflict.

I believe Haskell's GHC compiler has "fusion" which allows it to wrap chains of maps/filters/folds into a single tight loop. That way you keep functional style, but get performance of writing it imperatively.

Re:Why functional programming? by RyanZAG on Tuesday December 24, 2013 @03:28PM (#6961022)
You're getting a bit bogged down in details, I meant it more as a general case. There are numerous cases where it is simply more efficient to be operating directly on data - the most used example I can think of are fragment and vertex shaders. It's irrelevant to the issue anyway though: simply having the ability to do something does not make it the best way to do something. You could code in a composable and immutable way using FORTRAN or COBOL if you tried hard enough.

The OP was asking for cases where you'd prefer to be using FP over the type of code he is used to. Manipulating blobs of sensor data are simply unlikely to be a productive use of FP - although it could certainly be done. However, calculating statistics from that data is going to be a place where FP would shine and would be a good choice for it.

Not everything is a nail simply because you can spend hours hitting it with enough transformations to make it look like one.

EDIT: Thinking about it, fragment and vertex shaders actually seem like a very good place to use FP.

Re:Why functional programming? by MichaelGG on Tuesday December 24, 2013 @11:45PM (#6962208)
Even when doing direct mutation of a byte array, FP can come in handy. The key part is being able to pass around and return functions. While I don't have experience "manipulating blobs of sensor data", most code can benefit from passing functions around and using closures. Even in otherwise imperative code, using folds and maps may make things clearer. Although, it might not be practical due to performance reasons.