DEV Community

Zelenya
Zelenya

Posted on

Scala is one of the best ways to learn Haskell

First, a reminder: You DON’T NEED TO learn Haskell — that’s not what I want to talk about. I genuinely want to talk about learning Haskell, and Haskell specifically — not functional programming.

The following might interest you if you want to get into Haskell for personal reasons (if you think it’s cool, well-paid, or whatever). If not — idk…


📹 Hate reading articles? Check out the complementary video, which covers the same content.

Haskell is tough to learn

People constantly report about their frustration with learning Haskell. Working professionals already have some experience and expectations from using a language. For example, a Java developer can pick up Go and carry over most of their knowledge, while Haskell can crash all their assumptions about programming.

How is it that I know how to connect to databases, serve http, make decent uis, or all the other cool stuff — but then I can’t simply print a variable in Haskell or get the value out of some box?!

We can blame it on education, learning resources, skills, or whatever… but the thing is: there are too many things to joggle in Haskell. Imagine a Java developer. If they want to learn Go, they need to learn new concurrency mechanisms, pay some attention to syntax (still C family), unlearn inheritance, resist using abstract factories, get used to a couple of other things, and that’s pretty much it (I know, it’s a bit oversimplified).

But then imagine them learning Haskell — now there are more unfamiliar faces: laziness, purity, IO, type classes, immutable collections, entirely different syntax, etc. — and see them getting crashed by the balls.

One step at a time

Scala is a multi-paradigm language that allows you to tame this gap and learn one ball at a time.

The most stereotypical example is starting with Scala as a better Java (a bit of new syntax and constructs) and then building on top of that: introducing immutable collections, other immutability, purity, type classes, IO, and so on.

If you don’t know how to do something in a “functional” way, do what you know until you learn how: write a for loop, print in the middle whatever you want, throw an exception — it’s your life, don’t let anyone tell you what to do. You’ll eventually figure it all out.

And then, at some point, you “just” get familiar with Haskell’s syntax and laziness, and you're good to go. It’s quite enough to contribute at a middle or even senior level. Yeah, there is still plenty to learn to be proficient. There is always going to be something to learn with Haskell.

The best part about this flow is it can be done at a personal pace. For instance, you can be productive for years with basic Scala + immutability + ADTs without fully grokking type classes and using IO, then grok type classes and be productive with that, and so on… And if you want to deeply understand the concept before moving to the next one, you can do it too. Good luck doing that with Haskell directly.

There is a reason that Scala’s logos is a ladder. (It’s a joke; please don’t quote me on that).

No silver bullet

This way of learning Haskell is not a silver bullet — it’s just one path, which I think is worth considering. It comes naturally to some, judging by dozens of people I know who learned Haskell this way. But might seem unintuitive or even stupid to others.

Sure, if you’re taking your time studying Haskell in school, it’s a whole different thing. But if you’re already working in the industry, want to invest your free time into learning Haskell and Haskell books and courses don’t work for you (because they’re either too long and tedious or jump over the concepts, hand-wave, and tell you to wait for explanation in later chapters), consider the Scala path.

Also, Scala is just an example I’m confident with. I guess learning via OCaml might be close enough. I can’t vouch for it — I don’t know anyone who learned Haskell via OCaml (not because they don’t exist, but because they are out of my bubbles). Something like Gleam or Roc could be good as well…

Also, if you have Rust experience, you can jump to Haskell right away because the gap is smaller. But I wouldn’t recommend learning Rust just to learn Haskell, though…

And if you come with a JavaScript background, PureScript or Elm is a good pitstop before trying Haskell.

You have to decide for yourself.

A metaphor

Look at it this way. Imagine you want to learn to be an artist.

You can start painting (with whatever medium), where you must joggle shapes, values, colors, light, and shadow. I’m not even talking about other fundamentals (like subject, composition, or perspective). This is just the minimum, and it could already be overwhelming.

That’s why lots of people start with something like drawing with charcoal and restrict to basic shapes and values. For starters, you don’t have to worry about colors or try to understand shadows — just treat everything as shapes. And later, add perspective, light, complex shapes, or whatever you like.

And, of course, some people directly pick up painting without drawing experience (and don’t get overwhelmed).

Top comments (0)