1. Is there anyone else on the forum who is interested in or using functional languages for their work?

I'm particularly interested in F# and although I have no immediate application at work for this language, I am enjoying the very different way it uses of looking at data processing.

2.

3. I think learning functional programming is useful, as a new paradigm. It is too easy to fall into the mindset that programs must consist of a sequential set of steps. Functional, declarative or parallel program models can provide insights and suggest new ways of solving problems.

However, I haven't done any functional programming for abut 30 years!

4. What exactly is functional programming? Can you try to give me the simplest definition?

5. Originally Posted by mmatt9876
What exactly is functional programming? Can you try to give me the simplest definition?
It is where all programming is done in terms of functions: things you pass a value to and get a value as a result, rather than a sequence of steps to be performed one after the other on data (procedural programming).

So in a functional programming language, you don't have any variables to hold the state of the program. Instead the state is implicit in the stack of function calls and their return values.

For example, to calculate the sum of a series of numbers in a procedural language, you could use a loop with a loop counter, the current value you have calculated, etc:

sum = 0
for i = 1 to n:
sum = sum + 1

In a functional programming language, you would write this as something like:

sum(n):
n = 1: return 1
n > 1: return n + sum(n-1)

So the only values in the code are the argument to the function and its return value.

A pure functional language doesn't allow any side effects; i.e. it can't change any state outside the function. This means that strictly speaking it can't print out any results! So all functional languages have ways of breaking the rules to allow that.

One of the advantages of functional languages is that they are much easier to analyse mathematically than most other languages which means you can use automated tools to prove that programs are "correct" (i.e. match some specification). There are a few procedural languages that have formal definitions and can be proved in the same way, but they aren't widely used.

6. Originally Posted by Strange
Originally Posted by mmatt9876
What exactly is functional programming? Can you try to give me the simplest definition?
It is where all programming is done in terms of functions: things you pass a value to and get a value as a result, rather than a sequence of steps to be performed one after the other on data (procedural programming).

So in a functional programming language, you don't have any variables to hold the state of the program. Instead the state is implicit in the stack of function calls and their return values.

For example, to calculate the sum of a series of numbers in a procedural language, you could use a loop with a loop counter, the current value you have calculated, etc:

sum = 0
for i = 1 to n:
sum = sum + 1

In a functional programming language, you would write this as something like:

sum(n):
n = 1: return 1
n > 1: return n + sum(n-1)

So the only values in the code are the argument to the function and its return value.

A pure functional language doesn't allow any side effects; i.e. it can't change any state outside the function. This means that strictly speaking it can't print out any results! So all functional languages have ways of breaking the rules to allow that.

One of the advantages of functional languages is that they are much easier to analyse mathematically than most other languages which means you can use automated tools to prove that programs are "correct" (i.e. match some specification). There are a few procedural languages that have formal definitions and can be proved in the same way, but they aren't widely used.
Thank you for the help, I believe I understand functional programming a lot better now.

7. Originally Posted by mmatt9876
Thank you for the help, I believe I understand functional programming a lot better now.
You won't find out that you don't until you try doing it!

8. Originally Posted by Strange
Originally Posted by mmatt9876
Thank you for the help, I believe I understand functional programming a lot better now.
You won't find out that you don't until you try doing it!
Of course. What languages and resources are best to begin with if you are interested in functional programming?

9. Originally Posted by mmatt9876
Of course. What languages and resources are best to begin with if you are interested in functional programming?
Well, the OP mentioned F# and, although I know almost nothing about it, it might be a good choice. Haskell is popular. My first experience was with ML.

(And what I meant by that comment is just that it takes a while to start thinking in the new way required by functional languages. But that is one of the things that makes it worth doing.)

10. Originally Posted by Strange
Originally Posted by mmatt9876
Of course. What languages and resources are best to begin with if you are interested in functional programming?
Well, the OP mentioned F# and, although I know almost nothing about it, it might be a good choice. Haskell is popular. My first experience was with ML.

(And what I meant by that comment is just that it takes a while to start thinking in the new way required by functional languages. But that is one of the things that makes it worth doing.)
Thank you. I mostly have experience with C++, Java, and C#.

11. Some popular programming languages that I have heard of that support functional programming or are entirely functional in nature include PHP, Python, JavaScript, Haskell, and Elixir.

12. Originally Posted by mmatt9876
Some popular programming languages that I have heard of that support functional programming or are entirely functional in nature include PHP, Python, JavaScript, Haskell, and Elixir.
Although many languages support functional programming, as one way of using them, I would suggest using a language like Haskell or F# that is specifically designed for it - otherwise it is too easy to just fall back on the programming style you are familiar with.

BTW if you are interested in alternative models of programming, you might want to look into some others. For example, a declarative language consists of a series of statements about relationships rather than operations to be performed sequentially. So if you write something like:
x = y +1
it doesn't mean calculate the value of x now, based on the current value of y. It means, the value of x is always 1 more than y. So, whenever the program ever causes y to change, then the value of x will be updated automatically. You don't state the order in when things are evaluated, the compiler and run time system does that. I think these are (or were) widely used in AI.

The hardest programming model I had to deal with was one where the processor only had content-addressable memory. In other words, you couldn't refer to memory addresses (not even as variable names) but only by the data they contained. I don't think I ever fully understood what I was doing, even though I managed to get some programs to run!

13. Originally Posted by Strange
Originally Posted by mmatt9876
Some popular programming languages that I have heard of that support functional programming or are entirely functional in nature include PHP, Python, JavaScript, Haskell, and Elixir.
Although many languages support functional programming, as one way of using them, I would suggest using a language like Haskell or F# that is specifically designed for it - otherwise it is too easy to just fall back on the programming style you are familiar with.

BTW if you are interested in alternative models of programming, you might want to look into some others. For example, a declarative language consists of a series of statements about relationships rather than operations to be performed sequentially. So if you write something like:
x = y +1
it doesn't mean calculate the value of x now, based on the current value of y. It means, the value of x is always 1 more than y. So, whenever the program ever causes y to change, then the value of x will be updated automatically. You don't state the order in when things are evaluated, the compiler and run time system does that. I think these are (or were) widely used in AI.

The hardest programming model I had to deal with was one where the processor only had content-addressable memory. In other words, you couldn't refer to memory addresses (not even as variable names) but only by the data they contained. I don't think I ever fully understood what I was doing, even though I managed to get some programs to run!
Thanks. If I decide I want to learn about functional programming I will look into learning Haskell or F#. Declarative languages sound interesting.

14. Can anybody recommend any good websites, apps, or books for learning about functional programming?

 Bookmarks
Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement