Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning Haskell with a view to learning Scala

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.

like image 737
jaz9090 Avatar asked Sep 29 '11 08:09

jaz9090


People also ask

Should I learn Haskell before Scala?

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.

Is Scala easier than Haskell?

Haskell has a simple syntax and easy to use with simple features, whereas Scala has complicated syntax and complex features. Haskell is concise, safe and faster to use, whereas Scala is also concise, fast and safer with many libraries support.

Is Scala similar to Haskell?

Both Scala and Haskell are statically typed languages, but Haskell's type system is arguably more powerful, in the sense that it provides more guarantees that are checked by the compiler. It also has superior type inference, which means that it places a lower burden on the programmer.

Is Haskell Worth learning 2022?

Is Haskell Worth Learning in 2022? Yes, Haskell is worth learning in 2022 because functional languages like it are getting more popular among big companies like Facebook. Functional languages are typically ideal for big data and machine learning.


4 Answers

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.

like image 96
Tom Crockett Avatar answered Oct 10 '22 04:10

Tom Crockett


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.

like image 38
Chris Turner Avatar answered Oct 10 '22 05:10

Chris Turner


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".

like image 26
Pere Villega Avatar answered Oct 10 '22 04:10

Pere Villega


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.

like image 32
cbrandolino Avatar answered Oct 10 '22 05:10

cbrandolino