Notices
Results 1 to 12 of 12

Thread: Functional Programming

  1. #1 Functional Programming 
    Forum Freshman
    Join Date
    Jan 2018
    Posts
    9
    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.


    Reply With Quote  
     

  2.  
     

  3. #2  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,642
    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!


    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  4. #3  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    What exactly is functional programming? Can you try to give me the simplest definition?
    Reply With Quote  
     

  5. #4  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,642
    Quote Originally Posted by mmatt9876 View Post
    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.
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  6. #5  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    Quote Originally Posted by Strange View Post
    Quote Originally Posted by mmatt9876 View Post
    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.
    Reply With Quote  
     

  7. #6  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,642
    Quote Originally Posted by mmatt9876 View Post
    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!
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  8. #7  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    Quote Originally Posted by Strange View Post
    Quote Originally Posted by mmatt9876 View Post
    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?
    Reply With Quote  
     

  9. #8  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,642
    Quote Originally Posted by mmatt9876 View Post
    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.)
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  10. #9  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    Quote Originally Posted by Strange View Post
    Quote Originally Posted by mmatt9876 View Post
    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#.
    Reply With Quote  
     

  11. #10  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    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.
    Reply With Quote  
     

  12. #11  
    Brassica oleracea Strange's Avatar
    Join Date
    Oct 2011
    Location
    喫茶店
    Posts
    16,642
    Quote Originally Posted by mmatt9876 View Post
    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!
    Without wishing to overstate my case, everything in the observable universe definitely has its origins in Northamptonshire -- Alan Moore
    Reply With Quote  
     

  13. #12  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    Quote Originally Posted by Strange View Post
    Quote Originally Posted by mmatt9876 View Post
    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.
    Reply With Quote  
     

  14. #13  
    Forum Ph.D. mmatt9876's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    868
    Can anybody recommend any good websites, apps, or books for learning about functional programming?
    Reply With Quote  
     

Similar Threads

  1. functional groups
    By tecnica in forum Chemistry
    Replies: 2
    Last Post: August 18th, 2014, 09:00 AM
  2. Replies: 102
    Last Post: April 19th, 2013, 03:17 PM
  3. Functional Analysis
    By Guitarist in forum Mathematics
    Replies: 23
    Last Post: May 10th, 2011, 08:05 PM
  4. Density Functional Theory
    By sox in forum Physics
    Replies: 7
    Last Post: June 6th, 2009, 07:02 PM
  5. Functional Integrated Bioelectronics?
    By ih in forum Physics
    Replies: 2
    Last Post: April 1st, 2006, 03:57 PM
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
  •