views:

1600

answers:

8

I've been using Haskell for several months, and I love it—it's gradually become my tool of choice for everything from one-off file renaming scripts to larger XML processing programs. I'm definitely still a beginner, but I'm starting to feel comfortable with the language and the basics of the theory behind it.

I'm a lowly graduate student in the humanities, so I'm not under a lot of institutional or administrative pressure to use specific tools for my work. It would be convenient for me in many ways, however, to switch to Scala (or Clojure). Most of the NLP and machine learning libraries that I work with on a daily basis (and that I've written in the past) are Java-based, and the primary project I'm working for uses a Java application server.

I've been mostly disappointed by my initial interactions with Scala. Many aspects of the syntax (partial application, for example) still feel clunky to me compared to Haskell, and I miss libraries like Parsec and HXT and QuickCheck.

I'm familiar with the advantages of the JVM platform, so practical questions like this one don't really help me. What I'm looking for is a motivational argument for moving to Scala. What does it do (that Haskell doesn't) that's really cool? What makes it fun or challenging or life-changing? Why should I get excited about writing it?

UPDATE: Many thanks to everyone for the responses. The consensus seems to be "try Clojure instead", which I think is a great idea.

I'd still love to hear from more passionate Scala advocates. I'll admit that first-class modules don't strike me as particularly tempting, but I am planning to read up on the new 2.8 collections library.

+17  A: 

Scala's killer feature (vs. Haskell) is Java interop. It interfaces seamlessly with Java and it's really natural to write alongside Java. Its goal was to bring functional programming to the Java platform (which has historically been dominated by, well, Java), not so much to push the boundaries of programming as a whole. If you like functional-style programming and you need to interface with Java, you'll have a much easier time in Scala than in Haskell.

Keep in mind that you don't need to be married to any one language. Use whatever is most appropriate for the situation. It might be Haskell. It might be Scala. It might be Ruby. They all have different strengths — and I don't mean that in the trite "Everybody's a unique snowflake" kind of way. Don't discount everything else just because you've found one thing you like.

Chuck
Thanks, Chuck—I know this is probably exactly the right answer (that Scala isn't really about boundary-pushing excitement), but I'm going to hold out a bit longer for something sexier.
Travis Brown
Well, part of it is where you're coming from. For Java programmers, Scala does look like something new and exciting. The trouble for you is that Haskell really is on the cutting edge of language development, so most languages will look boring by comparison.
Chuck
@Chuck: Yes, after Haskell I can't learn new languages (except dependently-types ones!)
Peaker
Compared with Haskell "Scala lets you interact with stateful Java libraries. After all, Java is very stateful." -- [JJinux]http://jjinux.blogspot.com/2008/01/haskell-well-typed-programs-cant-be.html
oluies
Scala seems to have been picked up by http://ppl.stanford.edu as the main infrastructure for their parallel computing platform
oluies
+16  A: 

I've found Clojure to be easier for natural language processing. I'm also in the humanities (Classical Languages).

Lisp dialects like Clojure have a long history in NLP, so you might be able to find some decent prior art, and it also has good Java interop.

Will
I think Clojure might also be more interesting to Travis, being part of the dynamic Lisp branch of the FP family tree rather than the static ML-ish branch that Haskell and Scala belong to.
Chuck
+5  A: 

Difficult question. Requires expertize in both Scala and Haskell. I think I have heard that Scala had an edge when it comes to type constructors, such as the stuff used in the new collections library.

At one point I wrote a message posting some of that stuff, but I ended up deleting. See, the problem is that there's a basic equivalency between Haskell and Scala for the most part. It's only at the edge that things differ, so you'd have to be proficient in Scala before you could appreciate anything it has over Haskell. And, then, it's stuff related to OO, which is not something someone comfortable with Haskell is likely to value much.

Daniel
+6  A: 

Since this question is also tagged Clojure, I hope I can say this here as an answer to your last question "What makes it fun or challenging or life-changing? Why should I get excited about writing it?"

Not to be disrespectful towards the Scala community, but I want to suggest you check out Clojure some more, for the following reasons:

  • It's a Lisp, which will change the way you think about programming. Most important thought here: in Lisp code is regarded as data too.
  • Clojure has better support for functional programming (immutability, pattern matching) than many other Lisps.
  • It's dynamically typed, which will give you a new experience if you come from a statically typed language
  • Lastly, it runs on the JVM and Java interop is dead easy.
Michiel Borkent
+17  A: 

Since you use the Clojure tag also, how about using that and treating this situation as an opportunity to learn a Lisp?

Clojure is similar to Haskell in that it is remarkably well-designed; you can't really sum up the joy of working with it by listing a bunch of features. Nevertheless, even considered separately, a Lisp macro system and Clojure's approach to time, identity and state (see the awesome Are We There Yet? presentation by Rich Hickey), really are very exciting and something well worth one's while to play with.

So, the above would be a short summary why it might be a good idea for you to pick up Clojure in addition to Haskell without even considering your need of smooth Java interop. As it happens, Clojure's interop facilities are fantastic. So there. :-)

Michał Marczyk
As a user of both Clojure and Haskell, I think you're absolutely right. One thing I've noticed is that Haskell often feels like it has a focus on language research (because, well, it does) while Clojure is more focused on writing applications.
Zak
+8  A: 

More or less the only feature that Scala has over Haskell is first-class modules. In fact, Scala as a language is closed over modules. This also means that type classes are first-class values in the language.

Scala also has dead-easy Java interop.

So, unless first-class modules are something you get excited about, or you need Java interop for something, Scala isn't really worth the effort if you're already using Haskell, except as another excuse for broadening your experience of languages.

Apocalisp
@Apocalisp: Can you clarify "... Scala as a language is closed over modules"?
Randall Schulz
@Randall: Yeah. Every Scala expression results in a module. More informally, "everything is an object".
Apocalisp
Allow me to plug Apocalisp's presentation 'Scala for Haskell Programmers': http://docs.google.com/present/view?id=dhmnf9cf_26cgst4zg8 . Don't forget the speakers notes.
retronym
A: 

Scala's partial application semantics are clunky compared to Haskell's because Scala isn't meant to be programmed like Haskell. (It can be programmed like Haskell, but it wasn't meant to be.) Consequently the language designers decided to make certain things easier to catch errors and encourage people coming from a Java background.

In particular, partial application requires special syntax because programmers coming from Java expect to usually use total application, so they want an error flagged if they accidantally used partial application without indicating that's what they wanted.

Ken Bloom
If you use partial application in Haskell without meaning to, it will flag up as a type error. As far as I can see adding special syntax may make it easier to decode the error messages while learning, but doesn't help after that. (Of course the syntax may have other reasons for being there: I don't know Scala).
Paul Johnson
@Paul: I originally posted this answer a seriously long time ago, but I just found a comment by Bill Venners explaining why scala uses the underscore to partially apply functions. He says "This is because Scala to have good cross compatibility with Java libraries needed to kind of adopt the overloading rules. So you could have an x method with one parameter and an x with two. So it doesn’t work to just do what they do in languages where currying is the default." http://enfranchisedmind.com/blog/posts/scala-not-functional/
Ken Bloom
+4  A: 

It depends:

how much do you care about OO?

how much do you care about static typing?

how much do you care about learning something totally different?

As Apocalisp said, Scala doesn't offer much over Haskell, in particular if you don't care about the OO part. Scala's syntax is closer to ML than Haskell, but with a more limited type inference, that makes it clunkier. Still, is a very powerful language, and if you want a decent static typed language in the JVM, Scala is the choice. Besides, the most interesting Haskell libraries end up adapted to Scala (eg: parsec -> parser combinators in the language libary, QuickCheck -> ScalaCheck). You can also do pretty interesting things in applicative programming with Scalaz ( albeit, again, clunkier than Haskell)

Clojure in the other hand is a Lisp. I guess that sums it up :) It has a very simple syntax, macro system, and out of the box concurrency abstractions. If you want to learn something totally different than Haskell, that's the choice.

GClaramunt
Just to clarify: my personal choice is Scala
GClaramunt