What is a functional language

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 13237 Views - Last Post: 02 February 2013 - 05:47 AM

#16 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: What is a functional language

Posted 17 June 2011 - 02:15 PM

So what you are saying is if you are writing a functional program you should use a functional language because of some performance increases?
Was This Post Helpful? 0
  • +
  • -

#17 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: What is a functional language

Posted 17 June 2011 - 02:37 PM

No. He is saying that you should use functional languages when you want the full arsenal of functional tricks. There are many cases when the functional paradigm can attack the same problem in a different way. Instead of OOP where you tell the program HOW to compute something, functional focuses on what the problem is and WHAT you need to solve.
Was This Post Helpful? 0
  • +
  • -

#18 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2857
  • View blog
  • Posts: 10,960
  • Joined: 15-July 08

Re: What is a functional language

Posted 17 June 2011 - 02:59 PM

Honestly dude, it comes across as if you aren't reading Raynes's essays, so if you are, then I apologize. But seriously, if you want to learn, then stop asking the same question over and over and read the response given to you. Believe me there...
Was This Post Helpful? 0
  • +
  • -

#19 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: What is a functional language

Posted 20 June 2011 - 07:37 AM

Quote

He is saying that you should use functional languages when you want the full arsenal of functional tricks.


What functional tricks?

So far the functional tricks that have been mentioned are concurrency and immutable variables. Which are valid points but rarely need to be used, and can be done with OO languages.

From what I got out of this, functional languages are necessary in certain situations when you don't want to worry about things like mutability.

For any other people who have the same questions as me I found a great page explaining everything about functional languages.

http://www.defmacro....mblings/fp.html
Was This Post Helpful? 1
  • +
  • -

#20 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: What is a functional language

Posted 22 June 2011 - 01:12 AM

I'm not sure how my clearer my posts could have been.

It isn't about what a functional language can do that an object orientation language can not. Truckers can drive the big rigs and I can only drive cars and small trucks, but that doesn't make them a better human. I've said a million and one times in this thread to *stop* worrying about what is 'better'. That's missing the point.

The functional tricks are that a functional language typically offers everything you'd expect from a functional language. They're designed to be function languages, and thus it wasn't tacked on as an afterthought as it usually is in OOP languages (see C#). The word 'trick' was used poorly here, because they aren't tricks. They're simply concepts implemented. Higher order functions, closures, etc. Instead of "some things are sometimes immutable", it becomes "most things are always immutable". There is a massive difference, but you wont really get it until you've experienced it.

I've been presenting you with examples. I'm not really capable of describing every single good thing about functional programming right here in a few posts. It's hard enough to do it as a chapter of an entire book. These are simply examples of a few things that are good about FP, not intended to be all-inclusive.

So, concurrency and immutability rarely needs to be used? Sure, in an OOP language, you'd probably rarely find yourself using immutability. That's the point. In a functional language, you'd have and use immutability, because it makes code safer, easier to reason about, and frequently easier to write and understand. I've made this point already, but it seems to go unheard. I don't know what planet you're from where concurrency isn't "commonly needed to be used" though, so I can't help you there.

Alas, we're back to "what does FP do that OOP can't" and I've answered this question in this thread several times. There isn't anything you can do in an FP language that you can't do in an OOP language. Turing completeness and all that. But, there are plenty of things you can do in an FP language that ends up being cleaner, clearer, more concise, and generally better than the same thing in an OOP language. Your next question will be "what?" and my answer will be "go read some functional code and compare it to equivalent OOP code" and if you don't get it then, maybe you just never will.

Google is a huge resource of information, as you apparently know. defmacro.org's articles are great, so good catch. I encourage future readers of this thread to check that link out. 9 times out of 10, his articles explain things better than me. Wikipedia is a fantastic resource as well. All in all, you can ask people "what is so great about functional progamming?" until the end of time, but you're not going to understand it until you've worked with a functional language and have experienced it for yourself.

To UziTech directly: I apologize if my posts weren't clear or thorough enough for you. I certainly hope defmacro.org's article helped you out better than I did. Some people have more trouble 'getting it' than others.
Was This Post Helpful? 0
  • +
  • -

#21 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: What is a functional language

Posted 22 June 2011 - 08:37 PM

"What is a Functional Language?"
...it's the shit right?
lol im still an OOP guy but OOP get's boring. FP is like the next frontier for me :)
Was This Post Helpful? 0
  • +
  • -

#22 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: What is a functional language

Posted 27 June 2011 - 03:25 PM

Hey, I'm still a tiny bit lost, although I can now see that functional languages prevent race condition scenario issues.

I recently participated in a challenge to solve a soduko puzzle. This entailed using three 2D arrays: Rows, Columns, and Regions. (because sudoku boards have 9 rows, 9 columns, and 9 regions made up of the same 81 cells on the board).

The indexes of these arrays are where the math became a complication. For example, Row[0][0] is the first row array's first slot. This implied that:
Region_Array_Index = x/3 + (y/3)*3
Region_Slot_Index = x % 3 + (y*3)%9


Where x is Row's array, and y is the slot on that array...

e.g. to find the which region Row[0][0] maps to, the algorithm is
Region[0/3 + (0/3)*3][0 % 3 + (0*3)%9] = Row[0][0]
#ie
Region[0][0] = Row[0][0]      

OR abstractly...
Region[x/3 + (y/3)*3][x % 3 + (y*3)%9] = Row[x][y]

#ie
Region[3][2] = Row[3][2]
Region[4][0] = Row[3][3]




I coded them into methods for my program as:
    def sq_array(x, y)
        return x/3 + (y/3)*3
    end

    def sq_slot(x, y)
        return x % 3 + (y*3)%9
    end

# in usage:
Region[sq_array(x,y)][sq_slot(x, y)]





I also wrote a function to return which Region is mapped to Row x and Column y, given simply x and y.

    def get_region(a, B)/>
      g_region = lambda { |x, y| (y/3+1)*3 - (3-x/3) }    # this mathematical function returns the region's INDEX to be used with SQ[bla]
      g_region.call(a, B)/>                                 # supply the function with the INDEX of the row and column you would like to find the region of
                                                          # I think there's a way to get it to solve backwards if I add the slot number to it too...
    end



Alternatively, I could have written it as:
def get_region(x, y)      
g_region = (y/3+1)*3 - (3-x/3)
    end



Do any benefits of functional programming apply to these kinds of situations? In one of my comments, I wondered if I could somehow use that same lambda function to solver for s, where s stood for the slot in the region (and wasn't expressed anywhere since I was just learning the syntax of it all at the time).

Are there any speed advantages/disadvantages to using lamda assuming that it's a single(multiple) thread(s) executing the code?

This post has been edited by NotarySojac: 27 June 2011 - 03:59 PM

Was This Post Helpful? 0
  • +
  • -

#23 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: What is a functional language

Posted 31 January 2013 - 10:44 AM

Let me see if I understand this portion of functional programming. The given code will computer forver on a list of values, and once you start it, it should never stop. If it hasn't computed the value you need as of yet, you might have to wait for a while, few minutes to a few million years? Does this mean, then, that it would work best on say, a mainframe, where the mainframe is constantly working on the solution, and the users are polling for the desired result? Maybe I'm misunderstanding.
Was This Post Helpful? 0
  • +
  • -

#24 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,037
  • Joined: 21-June 11

Re: What is a functional language

Posted 02 February 2013 - 05:47 AM

View PostPwn, on 31 January 2013 - 06:44 PM, said:

Let me see if I understand this portion of functional programming. The given code will computer forver on a list of values, and once you start it, it should never stop. If it hasn't computed the value you need as of yet, you might have to wait for a while, few minutes to a few million years?


When you say "the given code", are you referring to a specific piece of code posted or described in this thread? If so, which one? Or do you just mean "code generally written in a functional programming language"?

Either way what you describe doesn't really have anything to do with functional programming. It's sort of similar to how lazy evaluation works, but with lazy evaluation, values are calculated the first time you need them, not continuously. And of course lazy evaluation isn't a defining characteristic of functional programming languages (most functional programming languages are not lazily evaluated).
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2