Great explanation, actually. But one question. I thought functional languages were "pure" throughout. I mean, I thought the whole point of a functional language is that there are no side effects and every expression returns some value. How is "pure" distinct from "functional"?
Oh, no no. Pure is not required for functional programming. Functional programming is mostly defined as the ability to pass around functions as 1st class data types. In fact, I noticed on your GitHub you do some Python. Here is functional programming in Python: # Sum a list in Python using FP
items = [1,2,3,4,5]
function = lambda x, y: x + y
reduce(function, items) # => 15
# The equivalent in haskell:
foldr1 (+) [1,2,3,4,5]
Pure is a stricter form of functional programming, which Haskell enforces. edit: BTW, Haskell DOES have a steep learning curve, and the inherent recursion breaks my brain. Even simple things like:
`combos = []` `combos = combos + 'foo'`
hurt, because counterintuitively (to me, anyway) this winds up in infinite recursion. I'm very used to OOP so this sort of thing is hard on me. I'm old though.
You're stepping now into the "lazy" aspect of Haskell. You're allowed to have infinite recursion in Haskell because it is only evaluated when needed. I don't really want to get into it here since there are many resources online about it :) But this also isn't inherent to functional programming or pure function programming.
Re:Why Haskell is suited to IO
by mattdeboard on Monday July 04, 2011 @01:48PM
(#2727221)
Interesting, thanks for taking the time for in-depth explanations.
Also you don't need to use recursion too much, when writing Haskell code. You should stick to using combinators over your (recursive) data-structures. Think fold, map, filter, and friends.
Alas, you still have to be able to understand recursion to get anywhere.
"Pure" in this context is basically short for "purely functional." Most functional languages have exceptions -- notably for I/O. Achieving 100% functional behavior is, it turns out, really really hard, and that's what makes Haskell notable.
edit: BTW, Haskell DOES have a steep learning curve, and the inherent recursion breaks my brain. Even simple things like:
`combos = []` `combos = combos + 'foo'`
hurt, because counterintuitively (to me, anyway) this winds up in infinite recursion. I'm very used to OOP so this sort of thing is hard on me. I'm old though.
edit: I'm a little bummed out by the downvotes on my original question. It was an honest academic question I had and was answered splendidly. I was not attacking Haskell whatsoever. I apologize if anyone took it as anything other than an honest question.