What is the point of functional programming?
I worked with the haskell language for a while. Although it was a confusing and very difficult ride. I guess the best parts of THAT language were: 1. Type-safety. (As far as I know) Impossible to get exceptions since everything is clearly typed 2. Very easy to write functions as well as pass functions as arguments to other functions. 3. Shorter code for computations 4. Type inference and polymorphism: write a function and it will automatically define the types for you Although, writing GUI's or things like games are terrible to program. There was one guy that wrote a quake clone though. Pretty sick... Also I read somewhere John Carmack (creator of quake) saying functional programming is the way to go and we should see some of it's features in imperative languages. Already C# is supporting type inference and polymorphism..
a factorial function in a procedural language will look like: function factorial(integer n) -> integer var x, result -> integer; begin result := 1; x := 2; while x <= n do begin ans := ans * x; x := x + 1; end; return result end; whereas in a functional language it looks like: --recursive fact 0 = 1 fact n = n * fact(n-1) or fact n = fold(lambda x,y:x*y, [1..n], 1)
why would it be a pain to write stuff like games or GUIs in a functional language?
haskell seems to be the most interesting of the functional languages. How does it compare to the Lisp family, or to the ML family?
Also, what are the "killer apps" of functional programming languages? Things like C and C++ are great for systems programming and performance-critical applications (games and stuff) -> Operating systems, World of Warcraft, Javascript, Ruby, Python, PHP -> this site, facebook Others like Java and C#... umm, business programs? Lisp, ML, Haskell -> ?
Haskell is stateless. So you have to mimick state by passing on variables from one function to another on and on. I had to make a simple poker game. So I made functions for creating decks, I had to pass the deck to another function in my "Main". Like a snowball effect.. passing things on to create this game. For me at the time it was a frustrating experience. As to the lisp or ML families. I don't know how it compares. The reason we got Haskell is because my Uni is actively involved in Haskell development. - Killer apps: I think for mathematical computations. Not judging speed.. It's easy to work with numbers. For instance you can actually define an infinite list [1..] then use take 10 [1..] which would print the first 10 numbers. So you could define a fibonacci/prime/catalan number generator without worrying about termination, like you would with a while loop
Oh and parallel processing seems to be very hot with functional languages...
Are they powerful for paralell processing because of the 'referential transparency' property?
I'm afraid my knowledge of concurrency is fairly limited :( Sorry
Join our real-time social learning platform and learn together with your friends!