r/functionalprogramming • u/Secure_Employer132 • Jul 01 '26
Question Beginner in functional programming
Hi everyone, I wanted to ask how you would start from scratch in functional programming to understand it in detail. I'm a guy who comes from the imperative paradigm and I want to delve deeper and investigate about functional programming.
I'm learning Gleam and some Erlang to understand Beam, and I'm not sure if it's a good place to start. I feel like I'm lacking some theory. Any recommendations would be appreciated.
32
Upvotes
9
u/APOS80 Jul 01 '26
I would like to suggest Ocaml, I’ve tried scheme/Erlang before and I found Ocaml to be a very nice and useful language. It’s more general purpose than Erlang.
17
u/TomosLeggett Jul 01 '26 edited Jul 01 '26
Make a cute little toy app in Elm. Really recommend that language. It's got the simplicity of Go but it's purely functional.
I wouldn't say it's a language that'll stick with you forever, but it'll help you massively when learning the ropes of functional programming. It's a language you can pick up and learn in a week and come out fairly satisfied.
It teaches you the reducer model really well, which is a good abstraction for immutable infrastructure coming from an imperative background. The whole language is centred around a declarative abstraction of web app logic, where each event is a message, each message is a type, the state is a record called the model, the current model and the event message get slotted into an update function, that returns a new model with the computations applied, which then slots into the view function to re-render the HTML rather than mutate it.
It allows you to literally write web apps with no mutation, which reduces runtime bugs dramatically, one of the neatest things about functional programming in general.
5
u/cladamski79 Jul 01 '26
You could try https://www.hica.dev/docs/hica-for-beginners/, my goal is to make programming with hica very approachable for beginners (and veterans alike), hica is a functional, expression-based language. I like learning by practise, start with small examples and then dive deeper on a thing you really want to build.
5
u/Dazzling_Music_2411 Jul 01 '26
Erlang is a bit too hybrid, but OK. Use some Lisp on beam, or Elixir if you must, for a more functional experience.
Personally I would suggest you start with Scheme/Racket and the book "The Little Schemer", then "The Seasoned Schemer", but I don't know how committed you are to the BEAM ecosystem.
5
u/_DCtheTall_ Jul 01 '26 edited Jul 01 '26
An Introduction To Functional Programming Lambda Calculus
This book is amazing and way more approachable than the name suggests. Starts with untyped lambda calc (just two mathematical operations) and shows how you can build data structures and implement basic arithmetic using LC as the theoretical backbone. It also teaches you some Lisp at the end.
This book teaches you the thinking behind FP and the concepts can be applied to any language which supports first-class functions. Reading this book leveled up my JavaScript significantly.
5
u/11fdriver Jul 02 '26
I think Erlang and Gleam are good choices, personally. Erlang was my first functional language many years ago. They're languages that will grow with you.
Erlang is weird, but still small and readable. It's a good introduction to thinking in functional concepts like recursion, folds, higher order functions, etc, plus a very good intro to why FP is useful, e.g. concurrency and reliability. I think BEAM is a good learning environment with nice feedback and hot-reloading. Libraries are excellent, everything is super reliable and well-documented. Learn You Some Erlang For Great Good is the quintessential guide imo.
Gleam is new but great, particularly when coming from or moving towards other statically typed languages. All You Need is Data and Functions was a real eye-opener for me.
https://mckayla.blog/posts/all-you-need-is-data-and-functions.html
For learning theory, I don't think Haskell is a bad choice tbf. Haskell's not actually too impractical for real work, but it certainly shines in demos and pure FP concepts. The ceiling is high and the gradient is steep, but there are lots of great learning resources, though you might struggle to read complex code until you have quite a bit more nailed down. Tooling isn't as bad as some people say. OCaml is reasonably equivalent if you prefer the look & feel.
Clojure is a gorgeous little functional Lisp on the JVM; everybody should try lisp at some point. The emphasis on generic-ness and flexibility is a key part of why I think Clojure succeeds. Transducers would be a core concept to glance over to see the sort of thing I mean, they separate the 'doing things' code from the concerns of datastructures in an elegant way.
But imho I'd say you should take Erlang and Gleam a little bit deeper rather than trying to learn more languages at this stage.
4
u/_mkoussaSynth Jul 03 '26
Nobody has mentioned Elixir???
Elixir. https://elixir.hexdocs.pm/introduction.html
4
u/deciomsoares Jul 07 '26 edited Jul 07 '26
I'd add a couple of suggested readings:
3
u/PuzzleheadedFix8366 Jul 05 '26
elixir
4
u/TankorSmash Jul 01 '26
If you don't mind going headfirst into a new syntax, check out Elm. It's a mini-Haskell, so you can really understand the sorts of change in perspective you'd need compared to JS. Here's a 60 line demo, and see if you can add another button to reset the counter back to 0. This is the official guide for the language that helps out.
Gleam is good too, but it's a little more complex than Elm, but the syntax is a lot friendlier if you're used to imperative langs, but getting Erlang/BEAM running is tricky, whereas Elm is just
npm install -g elmor something, if you've got a Javascript dev env going.16
u/[deleted] Jul 01 '26
[removed] — view removed comment