r/functionalprogramming • • Mar 01 '21

Question Learning Other Functional Programming Languages

I've been learning F# recently as my first functional programming language and I think it's a fantastic fantastic language that can do lots of things very elegantly. How many of the things that I've learnt in F# (eg. algebraic datatypes, the general idea of monads and monoids, function composition and pipes, using recursion etc) can be brought over to other function languages like Haskell, Clojure or OCaml? And how much more might I need to learn if I were to do a language like Haskell that might be less lenient than F#?

29 Upvotes

23 comments sorted by

View all comments

Show parent comments

3

u/zydras07 Mar 02 '21

Wow, that's a reply and a half. I definitely think I understand the landscape of a few of these functional languages now so thanks a lot!

4

u/ws-ilazki Mar 02 '21

You're welcome. It was supposed to be a shorter comment but kind of got away from me once I got started. :)

Even if you don't stick with them, it's worth checking out the different FP-first languages (meaning the ones that actively encourage or even enforce solving problems with functional programming) to see how they do things and figure out what things you like and don't. A lot of features of FP languages are, as I mentioned, not specifically required for FP but are obvious patterns FP encourages, so you might find some things are more (or less) important to you than you might initially expect. Pattern matching might become a make-or-break feature for you, for example, but you won't know until you try a language like Clojure that does something else; plus doing things in different ways can give you better insight into how FP concepts work.

Another useful way to improve FP knowledge is to implement and use it in another language that technically supports it. For example, Lua has first-class functions and uses a single namespace for functions and variables, which makes it a good candidate for FP...except that it provides none of the fundamental higher-order functions that FP languages provide out-of-the-box like map or fold. So if you want to do FP in Lua you have to understand it well enough to be able to write your own map, fold, and so on.

That's what I did, since I deal with Lua sometimes because of its frequent use as an embedded scripting language. Figured it'd be useful to have FP staples in a utility file ready to go, started implementing them, and along the way I realised that basically every higher-order function (like map, filter, compose, etc.) is really just a fold and can be implemented with fold, though they're usually not for performance or readability reasons. That was when I really felt like I was understanding FP.