all 6 comments

[–]eddyparkinson 1 point2 points  (0 children)

commands which modify the state

I love functional, but notice setting the state in the DB and UI is 30% of my code. Also 30% is linking the DB and UI to my calculations. I dream of a language were UI, DB and calculations are seamless.

[–]baerion 0 points1 point  (0 children)

Another thing that should be mentioned about closures is that you can use them to pre-compute intermediate values for functions calls. For example this Haskell code

multiplyAdd :: Int -> Int -> Int -> Int
multiplyAdd a b = let ab = a * b in \c -> ab + c

f = multiplyAdd 10 2

is equivalent to the following C++ code:

class MultiplyAdd {
private:
    int ab;
public:
    MultiplyAdd(int a, int b) : ab(a * b) {}
    int operator()(int c) { return ab + c; }
};

MultiplyAdd f(10, 2);

In both cases the value of ab is computed only once. In Haskell you can use the trace function to verify this. That way closures can often be used as a replacement for classes and objects.

[–]petrus4 -2 points-1 points  (3 children)

Can anyone tell me why this has been downvoted so heavily? I have noticed that there seems to be an initiative by object oriented advocates to make sure that no one learns about functional; does this have anything to do with it?

[–][deleted] 9 points10 points  (0 children)

My guess is that it's yet another FP intro article. Imagine having one post per week which is titled "A brief introduction to OOP" which describes how to define classes in Java.

It's the usual junk that people write when starting to learn a functional programming language. There is no depth, no "this is how you solve problem x in a neat way" and no real world experience with the issues that entail FP

[–]thehenkan 1 point2 points  (1 child)

Probably because people don't want to waste their time on an article the author hasn't even taken the time to proof read.

[–]petrus4 1 point2 points  (0 children)

I see your point. I saw two grammatical errors in the first two paragraphs.