News for hackers. Stuff that matters.
Re:Don’t Be Scared Of Functional Programming by peaton on Wednesday July 02, 2014 @12:46PM (#7978009)
> The literature relies on somewhat foreboding statements like “functions as first-class objects,” and “eliminating side effects.

I personally find this view a little overbearing.

In "lay programmer's" terms, functions as first-class objects can often come down to being able to pass functions to other functions or function composition. Most of us learned about function composition in Algebra 2... So that's pretty straightforward even at its worst.

Eliminating side effects is equally straightforward in that all it means is that any variables outside the scope of a given function are not changed by the function.

Re:Don’t Be Scared Of Functional Programming by mneary on Wednesday July 02, 2014 @01:11PM (#7978147)
Function composition is very different from passing one function into another and the latter is definitely a concept that most Algebra 2 students would not be able to grok.
Re:Don’t Be Scared Of Functional Programming by peaton on Wednesday July 02, 2014 @02:02PM (#7978534)
I knew I was making a strong assertion when I mentioned function composition. I'm grateful for your feedback, but perhaps you could elaborate? I don't see why they have to be "very different". I think you called me on a certain case, but an example like this demonstrates that they are not so "very different":

    def a(b):
        m = 0
        return b(m)
Or even:

    def a(b):
        m = b(1)
        return m+7
I don't see how these are not a form of function composition. I'm definitely no expert. But I'd really appreciate an elaboration so I can learn from any mistake I'm making.
Re:Don’t Be Scared Of Functional Programming by mneary on Wednesday July 02, 2014 @02:34PM (#7978738)
Function composition is a single, special case of a function accepting functional arguments. You could define the compose operator as below:

    compose : (a -> b) -> (b -> c) -> (a -> c)
    a `compose` b = \x -> b(a(x))
However, there is a whole spectrum of additionally possible functions which can be built to accept functions as arguments. Here's a couple of example:

    partial3 : (Integer -> Integer -> Integer) -> (Integer -> Integer)
    partial3 f = f 3
    map : [a] -> (a -> b) -> [b]
    map [] f = []
    map (x:xs) f = (f x):(map xs f)
The first one takes a function and applies an argument, 3; the next one takes a list and a function and maps the list using the provided function. The idea of functions as arguments is a very powerful one, and from my understanding one with which people sometimes struggle.
Re:Don’t Be Scared Of Functional Programming by rapala on Wednesday July 02, 2014 @03:08PM (#7978974)
One way to look at function composition is that it is a function to which you pass two functions and out comes a function:

  compose :: (b -> c) -> (a -> b) -> a -> c
  compose f g x = f (g x)
I'm not sure about the math curriculum in USA but in linear algebra you have functions that operate on functions.
Re:Don’t Be Scared Of Functional Programming by MidsizeBlowfish on Wednesday July 02, 2014 @01:36PM (#7978334)
Eliminating side effects is about a lot more than variable scope. One example would be reading from/writing to a file.
Re:Don’t Be Scared Of Functional Programming by dustingetz on Wednesday July 02, 2014 @01:50PM (#7978444)
I think it's an accurate description. The OS code that reads a file involves changing variables outside function scope, eg pointer writes to memory mapped hardware. Simply forcing all variables to be final, all the way down, really does eliminate all side effects.