r/functionalprogramming • u/j_gitczak • Jan 12 '25
Question Which functional programming language should I learn?
I have recently discovered the world of functional programming and I want to learn a functional programming language.
For most of my life I have programmed in Python and I have always liked its onelined expressions like list comprehension and lambdas.
I also value good error messages in a programming language (not some segmentation fault or NullPointerException bullshit), and this is also why I like for example Rust.
I study Mathematics so I like the idea of a programming language being "mathematical" which I heard Haskell being decribed like, and Haskell is what I initially thought would be the best to learn, but I don't want to exclude other languages, so that's why I'm making this post.
I don't plan on ending my functional programming journey on one language, so I want to first learn one just for fun, so it doesn't matter if a language is used in industry or not.
I would really appreciate some recommendations for the language I should learn.
15
u/Trequetrum Jan 12 '25
Lean 4 is a fantastic functional programming language as well as theorem proving language. I really enjoy working with it.
27
u/[deleted] Jan 12 '25
Ocaml ? It’s supposed to be a bit less strict than Haskell, so might be interesting just for that alone.
34
u/Ordinary-Price2320 Jan 12 '25
Try F#. At the basic level it looks almost like python, with lambda and list comprehension,but it has a fantastic type system.
22
u/NineSlicesOfEmu Jan 12 '25
OCaml was my first functional language and I still really enjoy it. There is a fantastic long youtube series about it that I would recommend: https://www.youtube.com/watch?v=MUcka_SvhLw
10
u/raxel42 Jan 12 '25
If you are from Java - learn Scala. If you are from C # - learn F#. Eventually, you will learn Haskell 😉
9
u/rodrigo-benenson Jan 12 '25
Haskell, Ocaml, F# should be your prime targets.
30
u/[deleted] Jan 12 '25
Just learn Haskell. You don't have any requirements that'd really push you towards a particular compilation target or whatever. Haskell is a purely functional language, unlike lisps, so it's ideal for learning functional programming.
12
u/KittenPowerLord Jan 12 '25
I think Haskell is the best choice if you're curious about functional languages, because it is the most different from the languages you seem yo have used before. You'll have to completely change your way of thinking, and after some struggle, you'll really get it. After that any other functional language will be simple
In contrast, I think smth like OCaml isn't different enough (for example, it allows mutability), and you'll be trying to write code like you always did, and adopting the functional mindset will take more time
6
u/tesilab Jan 12 '25
If you want to learn functional programming, don’t be practical about it. If you are doing it to learn, I would go with Haskell. OCaml is a great practical choice, or F# might really appeal if you want to be productive in the .net ecosystem. But these choices would allow you to fall back into non functional approaches to solving problems, which is something you can always do by adopting a more pragmatic language later — after you’ve learned how to think in Haskell.
16
u/delfV Jan 12 '25
I recommend some Lisp (like Common Lisp, Scheme, Racket, Clojure, Fennel, Jannet or Hy - this one compiles to Python). You will not only learn functional programming but also interactive programming which isn't available in any other programming language (family) beside Lisps and Smalltalk
4
u/cessationoftime Jan 12 '25
I find Scala and Rust to be the most effective/enjoyable to work in. I have not had very good experiences with Haskell (the tooling was more problematic than the language), I am hoping Idris will improve on it significantly.
And I think NixOs is mandatory for any serious programmer now, you should probably learn that before any new programming language if you have not already since it will let you set up infrastructure and development environments.
9
u/Fit_Ad5700 Jan 12 '25 edited Jan 12 '25
I like the combination of oo and functional programming that you’ll find in Scala. I learned it on coursera. I can heartily recommend Odersky’s free course there. I’m a mathematician too and the lectures are brilliant. Scala has a purity and elegance that I expect you’ll enjoy. The Object Orientated approach allows for more detail in modeling the world.
9
u/stellar-wave-picnic Jan 12 '25
For a type checked language I have enjoyed learning Purescript the most. This book was awesome: https://leanpub.com/fp-made-easier
Other than that I have worked with F# and made a few attempts at learning Haskell, which every time failed because of how clumsy it was to set up dev environment and package management etc... I have heard that the Haskell story should be better these days though, and I have a few Haskell based books that I want to read. Shouldn't be too difficult now that I am comfortable with Purescript.
Other than that I have enjoyed Clojure a lot. I think any lisp is worth diving into. After working with lisp for a while, you will feel that all other languages are unnecessarily complicated, verbose and has too many fancy syntactical constructs and you will long for the simplicity and flexibility of a lisp language.... But you will most likely also miss some proper type checking and the exception free experience, and thus return back to Haskell/Purescript/Rust.
11
u/ingframin Jan 12 '25
I am going to lose some karma here, but I suggest Julia. While not purely functional, it has all the basics covered with the added advantage that you can replace Matlab with it, as it is designed for numerical computations.
In Julia, you get higher order functions, immutable structures by default, multiple dispatch, iterators, function composition, currying, etc...
For example: https://scientificcoder.com/straightforward-functional-programming-examples-in-julia
If you want monads: https://monads-jl.readthedocs.io/en/latest/ and https://juliafunctional.github.io/DataTypesBasic.jl/dev/
The only caveat is the lack of Tail Recursion Optimization and thus more emphasis on loops than on recursion.
BTW, you can use functional style also in Python, without really the need to learn a new programming language.
6
u/thallessellaht Jan 12 '25
Haskell.
3
u/king-1011 Jan 12 '25
I started with Elixir given its usage in distributed systems and it's wonderful to use. But keep in mind sometimes functional program can be more verbose than the imperative one e.g. two pointers.
5
u/P3riapsis Jan 12 '25
Perhaps an unusual suggestion, but if you're a mathematician then you might find Agda interesting, although writing something practical in it is pretty hard at the moment. It's dependently typed, which means you get a lot of interesting maths-like stuff in the type system, such as existential and universal quantification.
This allows for some interesting stuff that isn't common in programming languages. For example, in most functional languages if you want to write a function that fails on a given condition, you might wrap the output type in a maybe monad to allow you to output nothing in that case. In agda, you often can instead require a proof that the condition to have well defined output is satisfied, and then you don't need to wrap the output in a maybe monad.
2
u/fosres Jan 12 '25
I would suggest you figure out what you want to do with computing first? What real life benefit are looking forward to benefit yourself and others with. Find the community of people that have a reputation for solving that kind of problem. Then pick up their programming language--whatever it is. The technical features of the language are less important. What's more important are the people you get to work and the ideas you communicate to each other using that language.
2
u/SteeleDynamics Jan 12 '25
SML
2
u/willehrendreich Jan 12 '25
I love fsharp, and I hear great stuff about ocaml
2
u/blizzgamer15 Jan 13 '25
I started with F# so I could leverage all the dotnet stuff. I really enjoy it
2
u/Tempus_Nemini Jan 13 '25
Haskell || Ocaml
2
u/cloudsandclouds Jan 13 '25
If you study math, try Lean! As of Lean 4, Lean is a general-purpose functional language—in which you can also rigorously prove mathematical statements.
There’s a lot of community support as well! :)
2
u/Routine-Winner2306 Jan 13 '25
Look.. Haskell was a one way trip for me. I also just knew imperative languages and when I started learning Haskell it was mind blowing... I can't recommend anything really but this was my experience. I hope it help somehow.
2
u/BinaryBillyGoat Jan 14 '25
Functional programming is a paradigm, not a type of language. You could use the languages you already know and focus on building pure functions/methods. After you have become familiar with the design patterns, you can switch to a language that is built with functional programming in mind.
2
u/TheSodesa Jan 14 '25 edited Jan 14 '25
Haskell, since the book Learn You a Haskell for Great Good exists, and once you have a decent understanding of Haskell, move onto Lean 4 (or greater version). The problem with Lean 4 is that any existing study materials are targeted towards people who already know functional programming, despite the names of some of them maybe implying otherwise.
2
u/TankorSmash Jan 12 '25 edited Jan 12 '25
If you're thinking of Haskell already, I strongly suggest trying Elm first! It's much simpler than Haskell, and you'll have a leg up when you start learning Haskell. Elm is the inspiration for Rust's error messages after all! It's basically unheard of to have runtime exceptions in Elm (but can happen), thanks to strict guardrails the language has. So not every webapp could use Elm, if it can, it's hard to beat!
Download the binary,
elm initto start a project, thenelm reactorto run.Sample Elm code:
eventually outputs
<div><button> - </button> <div> 123 </div> <button> + </button></div>(plus event bindings)On top of Elm, Haskell, and OCaml, you can also check out Clojure, which is the polar opposite, where it's more like Python in terms of being dynamically typed. So you don't have the benefit of Elm/Rust/Haskell, where if it compiles, its highly likely to work, but you can move very quickly
Another strong plus to Clojure is that IDE integration is unmatched (being able to run code just by highlight it the editor, and the terminal/browser runs that same code in the same instance). Error messages are some of the worst in industry as far as I'm aware though, and environment setup is a bit beefy. So its less that your program runs, and more like your editor is also running the program at the same time. Hard to describe but very cool!
Like Elm and Haskell, it's pure, but comes with easy mutation.
Sample Clojure code:
2
u/ruben_vanwyk Jan 12 '25
F# for sure.
0
u/[deleted] Jan 12 '25
[deleted] — view deleted comment
3
u/[deleted] Jan 12 '25
[removed] — view removed comment
0
u/[deleted] Jan 18 '25
[removed] — view removed comment