• he/they

developer | occasional composer | unable to spell


People of cohost who like functional programming, what convinced you of it's usefulness? I'm talking about pure functional programming like Haskell as opposed to using functional ideas like purity in other languages, which makes sense to me. Every time I try and learn Haskell, I either end up going "I could do this in a language I already know" or end up down the rabbit hole of "actually a monad is just a monoid in the category of endo functors". What is the use case that actually convinced you to sit down and learn haskell?


I understand that a lot of useful stuff like the Maybe monad and currying came from functional programming, but now that stuff is available in more flexible languages, is there still an advantage to Haskell? Do I need to learn category theory?


You must log in to comment.

in reply to @boscillator's post:

The thing to remember when looking at new kinds of languages is that nothing is going to get you new capabilities. It's a new way of looking at problems.

When I used to teach, I'd comment that "you can write crappy FORTRAN-like code in any language you want," to make the point that you need to give languages a chance on their terms, rather than fight to make them work the way you expect.

In functional programming, it's a matter of thinking of programming as transforming data in various ways. That fits some problems better than others and how some people think better than others. But there's (probably) no gimmick that makes it suddenly come into focus.

In my opinion, it's in a pure functional language like Haskell (or Purescript) where these features really shine.

You can have currying, monads and all of that stuff in other languages, but Haskell had a real need for it and - as a result - it is truly an inseparable part of the programming experience using the language (for better or worse).

The absence of side effects has a huge effect in how you design your programs, it is not something you can easily emulate in other languages. You have to be extremely principled (or use a framework I guess) to design something a la Haskell in other languages which are not made for it.

So Haskell is, in a way, the best language for writing programs in this style. You don't need category theory (I don't know anything about that). And the main reason to learn Haskell is because it's very enjoyable! If you don't think it is, that's fine, but I don't really agree with many people's opinion that "you can take what you learnt in Haskell-land to other languages". I would like to see someone using monad transformers in Javascript - it's not very practical. Most of the things that make Haskell very attractive are usually available just in Haskell or only make sense in Haskell.

That makes sense. I don't find it too difficult to keep side effects out of where they don't belong, but I suppose it would be nice to know that nobody else can do that without you noticing.

I'll check out monadic transformers. That sounds like the kind of "killer feature" I was looking for as a reason to learn pure functional programming (although the wikipedia page does appear to be written in category theory)

Monad transformers are a way of composing monadic computations (i.e: functions that return m a, where m is a monad). This is needed when you encode side effects as monads. But I wouldn't say they are a "killer feature", they are a solution the problem of monads not being composable (you can search for that if you want).

The real killer feature that Haskell has is being able to track effects in the type system. This tracking can be as granular as you want (the least granular is IO, which allows you to do basically anything). Tracking effects is pretty darn useful because it gives you a good guarantee that an effectful function you call may only perform the effects described in its type.

If you want to learn more about monads and monad transformers, I recommend the book "Haskell from first principles", which explains with a lot of detail their uses and their laws.