Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
AleCx042388818dyour problem with getting to grips with functional programming might come from the tech stack from which you are trying to apply it too. Remember, lambdas were just kinda barely introduced into Java.
Try reading around for it, getting the feeling for how they work in other langs, the written works of Alvin Alexander are pretty good. but take it bit by bit. Maybe try a purely academic endeavor through something like Lisp.
Elyz819218dI have no advice to offer that hasn't already been posted, i just wanted you to know you aren't alone in the struggle of trying to learn functional programming. It does get easier!
RememberMe1433118dLambda calculus 101
Suppose you have a sentence: 2 + 3
That is "add 2 to 3".
How would you generalize that to "add 2 to anything"?
We can replace 3 by a placeholder to fill in later, let's call it x. So the sentence now is 2 + x
Where did that x come from? This is programming, so you need to "declare" that the x is not actually part of the sentence, it just stands for something that you'll fill in later. So you write it with the declaration as \x. 2 + x
This is a lambda function (read the backslash as lambda). To use it, put something in front of it to apply it. Say, applying this to 5
(\x. 2 + x) 5
To evaluate this, replace the x with whatever you have applied, which here is 5. So,
(\x. 2 + x) 5 -> 2 + 5
In the untyped lambda calculus here, you can apply anything to anything. So for example, assuming you have something called cabbage
(\x. 2 + x) cabbage -> 2 + cabbage
is perfectly valid use of the lambda function (though it doesn't make much sense).
Notice that this function (\x. 2 + x) doesn't have a name. It's just represented by what it takes as input and what the computation it does. This is why Java/C++/Python etc. "lambda functions" are just another name for unnamed or anonymous functions.
Lambda calculus is a bunch of systems for representing logic and computation (actually, all of mathematics) in terms of lambda functions and rules for manipulating them. The most basic rules are abstraction (i.e. "generalizing" something by sticking a placeholder and then declaring that placeholder, thus making a lambda function) and application ("specializing" a lambda function by putting something into that placeholder) (you'll notice that abstraction and application are opposites of each other, this is a common pattern).
This is questionably useful for functional programming tbh because FP doesn't really use the pure untyped lambda calculus, but the ideas are all from here.
10Dev71518dThank you all!
I ranted because I felt like an idiot, but you guys have been unbelievably supportive
This community is awesome
Ranchonyx627318dI feel you, I'm a full blood java person -.-
AleCx042388818d@10Dev we've all been there man :D one thing that I respect a lot is devs that go up and say "I don't get this shit" rather than trying to convince others that they have the knowledge for it. Admitting not knowing something is the first step and you seem to be on the right track. Keep going at it, move your mental model from focused and diffused as necessary in order to grasp these concepts and I know you will eventually get it! Have fun bro!
beleg342017dIMO it would be way more interesting if you learn lambda calculus (and generally type theory) from the maths perspective, rather than programming,. And it could even be easier. Although good learning material out there is equally hard to find on both sides.
Ranchonyx627317dProblem is, your little java world has functional stuff...muahabab