Tuesday, January 8, 2013

Scala vs F#

I suspect the reason why people say Scala is more OO and F# is more functional actually has little to do with functional programming per se: it's because F# is more oriented toward ADTs and Scala is more about OO. Since ADTs package functions in modules instead of object scopes, this gives F# a more applicative, function-oriented feel, even though there's really no technical difference between F# and Scala in terms of what you can express functionally. It's not that you can't do OO in F# or ADTs in Scala, it's just a matter of the native idiom leaning one way or the other.

If you want to understand ADT vs OO, the best paper I know is here:http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf (hat tip to Lambda the Ultimate). Essentially, in ADTs there is a hidden, shared implementation: the black box obscures the class implementation, but doesn't obscure the objects within the class from each other. (This is like C++ "private".) In OO, the public interface is the ONLY interface: every object is a black box. ADTs are suitable for efficient abstractions like sparse matrix multiplications which need access to each other's internals. When people say "object-oriented" they are often not clear on whether they really do mean object-oriented programming or ADT programming. Certainly C++/C#/Java/etc. are schizophrenic about which style they are trying to support. (For example, an "abstract class" in C++/C#/Java is a hybrid of interface and implementation, which makes it neither/both OO nor ADT. However, a Java interface is pure OO.)

--
Hahahahaaaa!!! That is ME laughing at YOU, cruel world.
    -Jordan Rixon

I could not love thee, dear, so much,
Loved I not Honour more.

No comments: