Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> But the functional part gives no guarantees of referential transparency or immutable state, so the killer value of FP is lost.

I don't think I agree here. First, the language's type system can give you those guarantees where you need them. (Even Haskell has unsafePerformIO...)

Second, a lot of the "killer value" comes from first-class functions (and in statically typed functional languages, type inference). Coming from Ruby you may not see the huge benefits these would give over Java... ;)

Finally I disagree with the "kinda-sorta" label: The entire Haskell standard library could be rewritten, more or less, in Scala. How is that "kinda" functional? Likewise, obviously any Java code has a direct scala analogue... and with the Dynamic trait, you may even be able to write direct translations of ruby/smalltalk/python-style code too, after a bit of plumbing.

Most (any?) "kinda-sorta" lies with the programmer, not Scala. ;)



     a lot of the "killer value" comes 
     from first-class functions
Dealing with first-class functions in Scala is awkward (getting and returning functions requires juggling with generics, currying is half-baked), and if you are ready to make that compromise it can be argued that Java doesn't need first-class functions as long as it has anonymous inner classes.

     in statically typed functional languages, 
     type inference
Scala doesn't have the Hindley-Milner type inference that ML/Haskell have. It only does local type-inference, saving you from some boilerplate, but other than that it doesn't and cannot have type-inference where it is truly needed - in the declaration of functions / generic types.

    The entire Haskell standard library could be 
    rewritten, more or less, in Scala
Haskell relies a lot on type-classes for its polymorphism, which aren't really possible in Scala, and if you are going to work around that, well, the entire Haskell library could be rewritten in Java too with those workarounds, only with more boiler-plate.

The question is, does Scala provide enough value to bother with its deficiencies (the type system is more complex and awkward, the generated code more inefficient especially for Android, which doesn't have the luxury of the Java SE GC).

Well, it does, but for Android at least, a version of Java that had local type inference and a lighter syntax for instantiating anonymous classes -- would have been so much better. And personally I'm not ready to commit to C++ version 2.


It seems you don't like Scala, but I don't think your complaints accurately represent the language.

Scala doesn't have H-M type inference because H-M can't handle subtyping. You don't miss it, though. Declaring functions and generic types is hardly arduous, and indeed necessary to resolve that very same ambiguity that stops H-M working. In Haskell it is common practice to declare types for functions and other top-level definitions. Scala imposes about the same burden.

  Dealing with first-class functions in Scala is awkward 
  (getting and returning functions requires juggling with  
  generics, currying is half-baked)
Currying is not idiomatic in Scala. But other than that -- what? This makes no sense to me, as someone who write Scala most days of the week.

  Haskell relies a lot on type-classes for its polymorphism,
  which aren't really possible in Scala
Read "Type Classes as Objects and Implicits" (e.g. http://lambda-the-ultimate.org/node/4039) for how type classes are possible in Scala.


Scala's support for implicit parameters lets you do most everything you can with type classes. Plus, implicits have scope in Scala, so can choose which you wish to apply in a given context. With type classes the scope is global, so you're stuck with one implementation per type per project.

Unfortunately, I couldn't find a specific paper on this, but I've seen a talk by Bruno Oliveira on the relationship between implicits and type classes.


Perhaps http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf is the paper that you're looking for?


Yes, that's it. Thanks.


> a version of Java that had local type inference and a lighter syntax for instantiating anonymous classes

Isn't this ... Scala?

Sure, it has a lot more too, but there's zero obligation to use every single feature.


No.

That was my tongue-in-cheek remark about C++. Using a subset of C++ is exactly the same argument people have been making for years. The problem with that line of thought is that you're never working only with your own code (that, and the fact that Scala is not optimized for your subset).

That's the bad thing with a language born out of lots of compromises -- while initially a pragmatic choice, if it's popular it only grows uglier and uglier until it becomes the bottleneck of the industry.

If you don't believe me that Scala is ugly, try explaining a "Hello World" to a beginner that was never exposed to programming, taking the sample out of the official documentation, preferably without resorting to a cargo-cult style explanation of "just do this".

Here, I'll get you started:

   object HelloWorld {
     def main(args: Array[String]) {
       println("Hello, world!")
     }
   }
You have to explain -- (1) what are functions + (2) what are those singleton objects, with OOP sprinkled in between + (3) why functions have to be declared inside classes or singleton objects + (4) what are generic types + (5) the "main" entry point.

Compare this to the Python version:

    print "Hello world"
Or the Haskell version:

    main = putStrLn "Hello, World!"
Both of which only require an explanation of functions + the main entry point in the Haskell case. Yeah, the Scala version does more - that's the problem with ugly, it cannot scale from simple to complex easily.


I think we're talking past each other. First, I'm talking about capabilities, not aesthetics. Also not on the list of things I'm discussing: teach-ability.

Second, you asked for Java+1 ... then you post a code snippet that's pretty much exactly that, and tear it to ribbons. Let's be consistent.

On scaling from simple to complex:

There's a wide variety of techniques used to create abstractions, which (speaking generally) is how to tackle complexity. (Modules, OO, message passing, functional abstractions...)

On this front, Scala is remarkably uncompromising: The language designers have chosen to provide as many of those techniques as possible (and even add a new one or two of their own along the way).

Maybe that's overkill for scaling from simple to complex -- but I can tell you it's incredible for scaling from complex to really complex.


I think the only thing your hello world example proves is that hello world examples don't really demonstrate the overall complexity of programming languages very well, especially when you try to use it to say Haskell is easier to explain. Sure the Haskell version of Hello World looks simple but, once you get even a little beyond that example you start having to explain MUCH more complicated subjects such as currying, monads, functors, typeclasses, etc. Don't get me wrong I love Haskell but it certainly isn't easier to learn then Scala even if the syntax is less verbose. I don't really get your argument that Scala code does not scale to solve complex problems; I would actually argue that Scala does that very well. Now I will agree that some aspect of Scala syntax are ugly but overall it seems to do an okay job unifying object oriented and functional programming while remaining accesible.


That's a very contrived example which certainly falls apart in Haskell as soon as you do anything relatively complex (Python I would agree is a perfect language for learning to program).

I think it's also safe to assume that one of Scala's design goals was to make it accessible to Java developers, not beginning programmers.


> The entire Haskell standard library could be rewritten, more or less, in Scala. How is that "kinda" functional?

Surely all that means is that Scala is Turing Complete, not that it is purely functional.

Also, you use the "more-or-less" qualifier whilst disagreeing with the "kinda" qualifier, even though they are "pretty much" synonymous.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: