Hacker News new | ask | show | jobs
by BoiledCabbage 2389 days ago
I'll post this again "If you are interested in learning functional programming do not learn about monads".

There is no practical justifiable reason to learn about monads unless you already know Haskell. And there is no reason to learn Haskell unless you already know another statically typed functional language.

If you are interested in learning functional programming then either

Learn dynamically typed functional programming and pick Clojure (or Racket).

Or learn statically typed functional programming and learn Elm then F# (or OCaml).

Haskell is the worst language you could choose to learn FP. If you're trying to lean FP, stay away from it. If you're a huge FP advocate don't push it. And finally monads tutorials are the white noise at the end of a wrong way track in learning about functional programming.

Outside of Haskell, monads are about as important in terms of learning, knowing and effectively using functional programming languages and concepts, as braces being on the same line or next line is important to learning about general programming. It's not.

Does that mean no-one can ever mention a monads, no of course not. But it's such a tiny topic, that it's absurd it gets so much discussion like it's some key to learning fp or some incredibly crucial concept. It's not.

3 comments

I use OCaml, and monads also come up in OCaml code. Monads may not be as essential to understand in OCaml than in Haskell because OCaml doesn't use them to track IO in the type system, but people use them in OCaml to chain options and results. In fact, OCaml 4.08 introduced syntactic sugar that makes functor, applicative, monad usage more convenient. I'd say that monads are something that non-Haskell functional programmers should learn.

Monads also turn up with lists (flatmapping) and promises. Although you don't need to know what a monad is to flatmap a list or use promises, I'd say that being aware that lists have a monad instance or that promises have a monad instance provides insight.

Outside of the terminology and terrible, terribly abstract explanations, I find an understanding of monads to be greatly important.

> Outside of Haskell, monads are about as important in terms of learning, knowing and effectively using functional programming languages and concepts, as braces being on the same line or next line is important to learning about general programming. It's not.

For example, understanding that Promise in JS is a monad helped me figure out how to transform and combine event-triggered functions in a clean manner into promises with shared state, that had a guarantee on execution order.

And every programmer already knows monads once they start to use design patterns in lists, option, promises, io, etc.

> Haskell is the worst language you could choose to learn FP.

Why?

Can't post full thoughts now, but will cover a few points.

Haskell has an extremely steep learning curve. And you have to make it very far up that curve to begin to see or understand any of the value you're getting from FP. Up until then, it's just different and it's hard to see why you're jumping through all of these hoops when you could easily use a non FP language. You have to pay very significant signiticant learning costs before the benefits of any new insights stary to outweight those costs. Elm in contrast you can honestly learn in a weekend and demonstrates 60% of the values a user gets from FP. Very high ROI for expanding your knowledge of programming ideas and approaches.

Haskell evolved as a language to explore programming language ideas in, as a result it is filled with warts. You still need to learn and deal with a lot of those warts to be decently productive, none of those warts are relevant concepts just warts. You also need to be perfect and jump through a lot of hoops with strict adherence to all the rules to get things working. In contrast F# allows you to be non strict in your application of FP concepts. This is actually really beneficial for learners. It allows for separation of concerns - apply the new concept your learning now, and do everything else in the way you're accustomed it. Its roughly equivalent to updating a codebase with gradual typing. Your a lot more likely to be successful if you can add typescript typing one file or area at a time, than if typescript only worked if all of your files or non of your files had types.

Also Clojure (and F#) rely on the JVM and .NET so a lot practical use cases are already solved and solved well. As well, a lot of your existing knowledge will transfer over.

Finally once you've learned those core FP concepts Haskell is significantly easier to learn so you can easily dive into the Haskell unique parts.

There are other thoughts, but this should be a good jist.

Interestingly, I started off with Elixir & Elm and then moved on to Haskell. Elixir & Elm both feel like DSLs with abstraction level purposefully constrained relatively low. A lot of the concepts in those languages didn't make sense until I started picking up Haskell.

I don't really know if it's ultimately worth it or not but as a programmer I want to evolve by raising the abstraction level in my code. Haskell is the perfect platform for that.

Btw any examples of those warts in Haskell?