Monday, March 8, 2010

Robert Fischer Finally Admits that Scala is Functional

Robert Fischer says

If your language doesn’t lead people to re-discover point free programming at least in the small, then the language really isn’t taking function manipulation and functional language type conceptions seriously.

Thus Fischer has finally recognized that Scala is functional.

val double : Int => Int = 2 * // point free function definition
List(1,2,3) map double /* removes one point from List(1,2,3) map {x 
   => double(x)} */

Thank you Robert for finally getting to the truth.

Oh, the Underscore

Now, Robert may object because I didn't combine map and double into one super function, mapDouble. Okay

val mapDouble : List[Int] => List[Int] = _ map double
mapDouble(List(1,2,3))

Crap, there's an underscore. Is it a "point"? Good question. And the answer is no. In fact, what it is is a hole in the expression. Oleg Kiselyov, somebody who actually knows about functional programming, says they're related to delimited continuations and what could be more functional than delimited continuations?

Also, Erlang Remains Unfunctional

For some reason Fischer really hates on Erlang. Point-free is definitely not Erlang's strong suit at all due to it's ability to overload on arity. I don't know why the Erlangers don't go picket his blog.

Post Script on Converses

David MacIver points out (correctly) that my post assumes that a statement implies its converse. To that I say "pffft, write your own damn parody, David!"

20 comments:

Daniel Spiewak said...

:-) Don't hate *too* hard on his opinion piece. Honestly, I can see where he's coming from (I've made a similar argument in the past). It's undeniable that Scala makes many critical functional idioms (like point-free and currying) a lot harder than they should be. The whole syntax is definitely biased toward the object-oriented side of things, which is a shame. I would have certainly preferred a bias in the other direction, but that's just me.

In truth, this whole argument is the same old "define FP" debate in disguise, and we all know how such threads always turn out.

Ismael Juma said...

Daniel,

After reading some of Robert's comments on that opinion piece, I am not sure why he should get a pass. Two examples follow:

http://enfranchisedmind.com/blog/posts/post-functional-scala/#comment-37370

http://enfranchisedmind.com/blog/posts/post-functional-scala/#comment-37402

Best,
Ismael

Robert Fischer said...

Nice. :)

Dean Wampler said...

James, your second link on delimited continuations appears to be broken.

James Iry said...

Dean,

Seems to be an issue on their end with serving that document.

mariachi said...

The original post is not much more than nitpicking, really. "Scala is not functional because programming in it feels different than programming in OCaml or Haskell".

Does this matter? Did someone stop calling C++ OO because some people didn't consider it OO enough? Did the sky fall because of it, or did the Taxonomy gods unleash their wrath upon us, lowly programmers, for the sin of wrong classification?

Yeah, I don't think so.

Ismael Juma said...

James,

You are very late to the party, this is what Robert's LinkedIn page[1] says:

"Robert Fischer is a multi-language open source developer currently specializing in Groovy in Grails. In the past, his specialties have been in Perl, Java, Ruby, and OCaml. In the future, his specialty will probably be F# or (preferably) a functional JVM language like Scala or Clojure."

What did he just call Scala? ;)

Ismael

[1] http://www.linkedin.com/in/robertfischer

Robert Fischer said...

Busted!

James Iry said...

Ismael Juma,

After reading that and his comments to Martin I've mentally moved him from "merely ignorant" to "trolling douchebag."

Robert Fischer said...

You're calling me a trolling douchebag? That's awfully harsh. I've actually appreciated the exchange I've had with Martin—it's really made the situation a lot more clear. Some of my characterizations of him were off (and there's still a few things I don't get), but I didn't realize that until we had a chance to talk.

Henrik Huttunen said...

D creator, Walter Bright, doesn't consider Scala as very functional ;)

"Neither C# nor Scala support pure functions or immutable data structures, which
are fundamental to FP. I don't see how they can be considered as
supporting functional programming."

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=107173

Unknown said...

Henrik, great link :)
I wonder what Walter Bright would think if somebody tells him that Java supports pure functions and immutable data structures...

Donna Malayeri said...

@Gabriel: Java supports functional data structures, but 1) programming them is a pain, 2) the JVM doesn't do any optimizations for them. You can write OO code in C (manual dispatch tables, etc), but this doesn't mean the language supports OO programming. Plus javac doesn't do any tail call recursion optimization, which is pretty critical for functional programming.

Donna Malayeri said...

...not that this changes the fact that Walter Bright is wrong on this...

Carlo said...

I have to say that this language is so functional but there are some people who don't understand that for example my friend named Sildenafil he's skeptical about that scala.

Robert Fischer said...

"I think it's fair to say that point-free style is not idiomatic Scala. If you ask me, it's not particularly missed." -- @odersky

Nick said...

Gabriel: Walter Bright didn't say if a language supported pure functions and immutable data structures then it is a functional language. He just said those 2 things are some of the prerequisites. Earlier in the discussion he said:"To me, the foundations of FP are immutability,purity, and closures, which got a lot of attention. Most of your pointsare already supported by D, although not quite as conveniently as inmany other languages."http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=107162Obviously Java not supporting closures stops it from being considered functional.Also, I may be wrong, but I don't expect that Java allows users to define their own immutable data structures, even if it offers built-ins. I'm pretty sure that's what Walter meant.

Sert said...

I'll be glad to share my own thoughts to you soon. Buy Zetia Online

Robert Fischer said...

Still not crazy to make this claim.

https://groups.google.com/forum/#!topic/scala-debate/aI81VLgk_Gc

"
(3) Basic features (mostly FP) are missing from parts of the library, causing unnecessarily verbose and hard-to-follow code.  (a) It seems like "re-invent |>" is the answer to a StackOverflow question about once a week.
That's intentional. I believe |> is not idiomatic Scala style; and I would tend to use method chaining instead. Generally, trying to do point-free style in Scala is a dead end." 

MizanHassan said...

Discount
Thanks. I was looking for an early reference. My memory was that he
didn't start advocating stabilizing nominal income until after WW II. 
Discount