46

I've read a few questions such as Scala vs Haskell discussing the merits of both languages or which to learn, but I already know that I'd like to learn Scala. I was a Java programmer at uni and now mainly use PHP.

I want to learn Scala as it looks like an improvement on Java for personal projects and I'd also like to learn a functional language to improve my knowledge as a programmer.

I am wondering if it would be a good idea to learn Haskell as an introduction to functional programming as it is purely functional so I'd properly learn it rather than haphazard using bits of functional in Scala without knowing why?

I'd also like to use Haskell for personal projects etc as it looks great, but I don't really see many real world applications of it, seems more used for academic stuff hence wanting to learn it to get the functional understanding then move on to Scala.

jaz9090
  • 951
  • 10
  • 22

6 Answers6

87

Speaking as someone who came from Java, and for whom Scala was a gateway drug to Haskell, I happen to think this is a great idea (learn Haskell first)!

Haskell is conceptually a much simpler language than Scala, and if your goal is to learn how to program functionally, you can't help but do so if you start with Haskell. By design, Scala supports a kind of "legacy mode" of coding in which you don't really have to change your Java (or PHP) habits too much if you don't want to. I think this is a strategic decision--and a good one!--meant to increase adoption amongst crusty Java stalwarts.

But that's not you! You're actually interested in learning something new... so why not go all-out? Learning functional programming in a pure setting, without the clutter and the temptation to regress into old habits, will crystallize the concepts in your brain.

Then by all means return to Scala and learn how it differs from Haskell; it is both weaker in some respects and stronger in others, but you will then be on a much better foundation to appreciate these differences.

Tom Crockett
  • 30,818
  • 8
  • 72
  • 90
  • 10
    +1 very nice written. 'Scala the gateway drug to Haskell'. It's true, you can go from Agda or coq to haskell. And from haskell to Scala. But usually you really don't want to because you are missing the features. Perhaps look at the talk 'running a start up on haskell', see: http://bos.github.com/strange-loop-2011/talk/talk.html#(1) To put it with humor: maybe (maybe!) by the time you master haskell perfectly, there will be a demand for haskell developers for commercial projects. And maybe by then everyone here writes learn coq! (or agda! ...or the next big thing) – mrsteve Sep 29 '11 at 10:21
  • 7
    I agree. Learning Haskell will remove you from the normal habits in a way that Scala can't. It will also take you away from the traditional object-orientation and learn you another way to think about classes (type classes). I can recommend the book http://www.amazon.com/Programming-Haskell-Graham-Hutton/dp/0521692695 – thoredge Sep 29 '11 at 10:57
  • +1: That was exactly my path: I knew Java, two years ago started learning Haskell, and now that I have some experience with Haskell I am given Scala a try. I think both Haskell and scala are amazing languages. – Giorgio Sep 29 '11 at 12:21
  • 1
    @mrsteve: To be fair, Scala does offer some things that Haskell lacks; for example subtyping + bounded quantification. This extra power comes at the cost of decidable type inference of course, and many don't consider that worth giving up. – Tom Crockett Sep 29 '11 at 22:50
  • 4
    Haskell is a gateway drug to all kinds of hard drugs like Coq and category theory :) – Tom Crockett Sep 29 '11 at 23:04
  • 6
    I wonder whether he'll ever "return to Scala" after he's been drawn in by Haskell's beauty ... :-) – hvr Sep 30 '11 at 12:38
  • I think that Haskell will conquer the world. If it doesn't happen, the world will be sad and boring for people who really love programming. – FtheBuilder Mar 09 '16 at 02:01
17

I wouldn't do that. If you go straight to Scala (your final aim) you save time. You'll learn functional programming anyway, but as Scala is "less pure" you'll be able to start writing programs in Scala usign some Java-like constructs, which will make the transition simpler.

Even if you go into Haskell, your first programs will be of less "functional quality" than later ones, as only practice improves that. Starting Scala your first programs will be of "less quality" as your first programs in Java or PHP were, but with practice you'll improve. Spending time in unrelated tasks hoping they MAY help, it can result in you wasting that time.

Focus on your aim. If that's Scala, go for it.

UPDATE: I believe this may be relevant to the question. It raises a point on productivity (deliver software) vs seeking "pure knowledge".

Pere Villega
  • 16,429
  • 5
  • 63
  • 100
  • I agree. Besides there is nothing wrong with using imperative style for certain things and functional style for the other if you're in Scala. Learning Haskell won't help you in making decisions as to which tool is best suited for the job. It will teach you how to eliminate imperativeness altogether, which is a different paradigm. – julx Sep 29 '11 at 08:32
  • 3
    +1 If your objective is to learn Scala, then learn Scala: most teaching materials assume a Java background so will explicity help with this transition, and notably **don't** start off by teaching you Haskell! – Luigi Plinge Sep 29 '11 at 14:18
  • Re: first programs being "less functional quality," by which I assume you mean "doing real-world things": OP will start picking up new concepts right away. It seems their main goal is to solidify concepts of FP. "Real world" applications are in many ways less relevant to the concepts of pure FP than the learning you get just typing in GHCi. – amindfv Sep 30 '11 at 05:09
  • @amindfv I meant that at first programs created with Scala will be more imperative than functional due to the mix Scala allows. Personally I believe that's not bad, as it allows you to learn by practice by improving code in iterations where each refactoring is more "Functional". It works for me to learn. Judging from votes on answers, people like more a different approach to learning, doing some detour to pick theory and then going back to the original aim, in which case that mix Scala offers becomes irrelevant :) – Pere Villega Oct 02 '11 at 16:54
17

I came to Scala from a Java background. Initially I just focused on Scala as a better Java. As time went on I started to use more and more functional concepts in Scala. Eventually I reached a point where I felt I needed a purer understanding of functional programming. It was at this point that I went away and learnt Haskell.

When I cam back to Scala I found it much easier to use a functional style and some of the the concepts I struggled with previously made much more sense.

You don't have to learn Haskell to become a good Scala developers, but I think once you get to a certain level in Scala that having a deeper understanding of functional programming concepts really helps.

Chris Turner
  • 400
  • 1
  • 7
7

The risk of starting directly from Scala, without having played any purely functional programming language first, is that you'll probably be drawn to the procedural solutions a bit too often.

I wouldn't try Haskell as an intro to functional programming, though: not that it's particularly hard - its syntax is amazingly terse - but it's definitely very peculiar (even in the peculiar world of functional programming) and I think you should try with a language you can port more easily to Scala, like Racket or plain Scheme.

To better understand what I mean, look at list comprehensions in Haskell, Scala and Scheme.

cbrandolino
  • 5,873
  • 2
  • 19
  • 27
4

I learned Haskell first and then Scala and never regretted. You will gain a much deeper appreciation of FP if you learn Haskell first. Your understanding of the concepts behind FP and why they are important will be seared in. Much of Scala is taken from Haskell (IMHO). It will make more sense when you have the Haskell background. Don't shy away! Your efforts will be rewarded.

Eric
  • 2,389
  • 1
  • 14
  • 9
0

For me, I want to learn Scala and functional programming; and, thus simply, I am learning Scala. My study material is Programming Scala. After I have read the early chapter on syntx and stuff, I have skipped chapter covering OO stuff and jumped to Chapter 8 which cover the functional programming stuff. There I let myself struggle with FP.

I read this scala code, which is written in FP way and analyze it. You want to learn Scala for "...an improvement on Java for personal projects." and Haskell for FP intro. So, it seems that first of all, you want to be productive with your java project and then grasp FP as a side effect. To be productive, you have to master the language. There are much to learn and master the language and the only way to master the language is that you have to write the code in that language. As you learn/use Scala, you can't avoid FP out right even if you want to. I have been reading the Scala blogs(the book too) and the authors always go out of their way to do explanation when it comes to FP concept. You don't have to worry about not grasping FP by going Scala route. Yes, you can draw inspiration from Haskell like this when you are learning Scala. Or as Chris Turner above have pointed out, you can delve into more FP when you are already productive with Scala.

You wanna go to point A, why not go to point A directly? If you go via the route of point B (Haskell), you will have to postpone your productivity as Pere Villega mentioned.

Community
  • 1
  • 1
Win Myo Htet
  • 5,377
  • 3
  • 38
  • 56