Learning OCaml before Elm?

I’m currently working through “Elm in Action”, which convinced me to get deeper into Elm after a couple of chapters.

However, I feel a bit lost with the language fundamentals (type system, the way how side-effects are handled etc.).

Would learning OCaml (or Haskell) help me get into that? (Since Elm targets browsers, implementing very basic things outside websites isn’t very helpful.) I currently work through SICP, so I have few issues with functional thinking, but some with types and the ideas of effects (or commands).

Any suggestions how to get deeper into the language?

3 Likes

I would say Elm is the best way to het into those languages as it is much smaller and cleaner. OCaml and Haskell have so many concepts, you get lost in these countries quite easily.

1 Like

I agree with this, but learning ReScript is also an option. I find elm simpler than ReScript, but if you have a strong imperative background then the opposite might be true.

1 Like

If your primary goal is to develop your skills in functional programming in general then my recommendation is to stick with Elm. It’s by far the most delightful way to learn fp imho.

When I first got interested in functional programming I started to learn Haskell but as other have mentioned it’s a much bigger language and echo system which made it hard to know where to start and what features to focus on. Somehow it just never really “clicked” for me.

I then switched to Elm and practiced fp by solving a lot of advent of code problems and suddenly everything just clicked. It was truly a delightful experience.

Thanks to Elm I’m now a full blooded fp enthusiast and I’m coding in both Elm and Haskell. Learning Haskell was soo much easier after I learnt the basics skills in functional programming with Elm.

To summary: my recommendation is to just go with Elm. :slightly_smiling_face:

2 Likes

Thanks for all the answers! So the consensus is to stick with Elm.

Any hints on how to practice language basics outside the browser, not limited to the REPL?

Any hints on how to practice language basics outside the browser, not limited to the REPL?

Online learning platforms (such as exercism) and challenges (such as advent of code, see Ryan’s videos) are a fun way to learn.

Also note that the REPL is not limited to what you type in one session. If you load the repl inside an elm package or app, you have access to all the modules defined there, so you can easily test multi-module code in the repl.

2 Likes

Ah, right. I just need to init a project, then I can import the code from that folder for testing. OK, that could work for me! Maybe I’ll try elm-mode for Emacs, so that I have a similar setup to what I use for SICP.

Thanks!

1 Like

Hello @patrick.bucher,

I’ll chime in with a different opinion, as someone still learning Elm and functional programming in general.

It took me a while to get used to the FP mindset that Elm introduced me to.

What works for me is learning other (many) functional languages in parallel, it helps me get a fuller picture, recognize patterns, etc. At least at the surface level.

I personally find that Elm and OCaml have a lot in common.

If you have the time and motivation to learn, I can recommend reading this awesome little book, and doing its exercises: https://johnwhitington.net/ocamlfromtheverybeginning/index.html

In it, you will learn the basics of functional programming, from a static typing perspective, and I feel you’ll be able to apply this knowledge to Elm. It’ll probably help you tackle better the later part of the “Elm in Action” book, where you get introduced to the mind-bending recursive types :slight_smile:

Good luck on your learning journey

4 Likes

Hi @benjamin-thomas

That looks like a decent little book that won’t take to long to work through. So I should give it a try! Thanks for the hint.

My problem is not the declarative style or recursion, since I almost finished chapter 2 of SICP. My problem is rather the type system; so this might be a good fit.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.