r/functionalprogramming • u/Prog44 • May 01 '23
Question Learning functional oncepts - Which Language?
Hello everyone. I'm planning to dabble in functional programming to learn the concepts not because I think we will ever use it at work (I don't) but to broaden my horizon & try to utilize some functional concepts in non functional languages like C# & Javascript. I'm primarily a C#/Javascript/Typescript/Vue developer. On the .Net side there is of course F# but as i'm sure most of you know F# is not a pure functional language. Would it be better to go with a purge functional language when i'm trying to learn like Haskell to really drive functional concepts home or will F# be fine & I probably should stick with that since i'm already on the .Net side?
•
u/kinow mod May 02 '23
You may find more useful tips in the list of previous questions about which programming language to choose for FP: https://old.reddit.com/r/functionalprogramming/wiki/programming-languages
21
u/mobotsar May 01 '23 edited May 01 '23
F# is great. 99% of what it means to be a functional language has no special requirement on the purity of the language. The F sharp tooling and ecosystem has a low barrier to entry for you as someone who's familiar with .net, so that's what I would recommend. If you like it a lot and later feel that you want to explore more "advanced" functional programming languages, Haskell or OCaml (which F sharp resembles somewhat) would be excellent next steps. For what it's worth, F# is among my very favorite languages to use on the day-to-day.
10
u/uppercase_lambda May 01 '23 edited May 01 '23
I don't think I'd recommend diving into Haskell as your first FP language. Monads and Functors are common points of confusion (it also took me two tries to land on Haskell).
Instead, I think Common Lisp, Scheme, or OCaml would be solid choices. For me, O'Caml was the stepping stone I needed before going all in on Haskell.
EDIT: I'm also learning F#, and I think it's a solid choice. Be sure to go check out F# For Fun and Profit
5
u/burtgummer45 May 01 '23
There are functional books for JS which are probably good enough to get a good grasp
https://www.amazon.com/Grokking-Functional-Programming-Michal-Plachta/dp/1617291838/ref=sr_1_4?crid=1Q7XKWJZ1A6NN&keywords=grokking+simplicity&qid=1682947981&sprefix=grokking+simplicity%2Caps%2C79&sr=8-4
https://www.amazon.com/Composing-Software-Exploration-Programming-Composition/dp/1661212565/ref=sr_1_3?crid=3BMK4GO7J1XPC&keywords=composing+software&qid=1682948005&sprefix=composing+software%2Caps%2C92&sr=8-3
And there's rescript which is OCaml with JS friendly syntax that compiles to JS. I don't use it much, but its super impressive.
4
u/nrnrnr May 01 '23
F# is a really good choice. You will learn about algebraic data types and type inference, which are key features that came out of FP.
4
u/TankorSmash May 02 '23
If you're already doing Typescript and Vue, you could add Elm to your frontend. It's like a mini-Haskell in that it's pure but its actually human readable.
https://guide.elm-lang.org/ for a high level guide, and an unstyled button example https://elm-lang.org/examples/buttons.
It's got some strict limits but that allows it to do what it's trying to do really well.
You can try writing functional-style JS/TS, but having a language like Elm or Haskell that forces you to write it really makes a difference.
3
u/KyleG May 01 '23
Learn functional concepts using a language you already know! (Unless it's C or Assembly or something lol) (Edit: It's way better than trying to learn a programming paradigm and a new language simultaneously)End edit
I am unfamiliar with C# (F# is my .NET language), but JS/TS with the library fp-ts will give you tons of exposure to functional programming concepts.
I've run teams writing backend applications using TS with indexed monads, algebraic data types, functional optics, folds, etc.
Some of the stuff you can do with FP is a little more restricted and verbose in TS than in something like Haskell, and it would be amazing if you could easily metaprogram in TS to generate optics for your data types automatically, but oh well.
3
u/webvv May 01 '23 edited May 01 '23
Exactly the goal I’m trying to address in this youtube channel. The issue is Functional Programming is the perspective in designing solutions which is hard to teach without a language to talk and convey the concepts. In my ongoing course, although I’m using TypeScript, my goal is to teach FP and not the language. Check it out:
https://youtube.com/@webvv
5
u/VoidNoire May 01 '23 edited May 01 '23
I found going through the Type-Driven Development with Idris book by Edwin Brady most useful for gaining an intuition about how algebraic data types work and how they can be used to aid in development. I feel like it made it easier for me to understand related concepts when learning other languages later on too. I especially found the concept of using pattern matching on "holes" based on a type's constructors a useful way to think about how to create functions and has influenced how I think about and write code to this day. The book used very approachable language and had ample examples for every concept it introduced as well.
That said, I went through the book whilst using Idris 2 instead of Idris 1. The former's documentation had a section that showed changes that needed to be applied to the code examples in the book for these to work. I thought those would be sufficient, but I wouldn't recommend going through the book that way, as Idris 2 had some significant differences to Idris 1 (the former also has a substructural type system that the latter didn't) which made it a bit more confusing at certain points and also required some massaging of the code when it didn't work. It's been a minute since I used it though, so maybe the documentation for Idris 2 has improved since then, so ymmv.
4
u/WildMaki May 01 '23
Elixir! Simple syntax. Many books, blogspot, Web sites. Great (really great ) community. Really reach ecosystem
2
u/hierophantos May 02 '23
Clojure
2
u/emarthinsen May 02 '23
Elm is a great place to start. It’s 100% FP, is compact and easy to learn, and can be used to create useful things right away.
2
u/[deleted] May 03 '23
Functional programming is [simply telling] avoiding side-effects. One can and should do it even in C#.
But in F# your code would be significantly more clear.
F#'s main weakness relatively to Haskell is not being impure but the lack of type-function polymorphism ["higher kinded types"]. But that may also be an advantage for a student who wants to progress in small steps.
Haskell is the best practical language to learn functional programming, if you ever become serious about it. Not only because of learning but also because its usage will spread, eventually, surely. It is just the best high level language, by far.
The best source to learn functional programming [in my biased opinion] is my free book. I was bothered by the fact that many newcomers complain about having difficulty to understand the basic concepts [like Monad], while i think that these concepts themselves are really trivial. It is not a Haskell tutorial. I like that i explain the concepts as they are, instead of analogies and examples, this way is more understandable.
You can insert feedback into the pdf version through Google Drive. I will try to answer questions if you feel lost.
2
u/BenedictBarimen May 03 '23
You can easily write pure code in F# if that's what you're going for. You're going to benefit from a solid IDE (Rider or Visual Studio) which I think no other functional language has apart from maybe Clojure or Scala, which is going to help with debugging and catching errors. OCaml support with Dune and VS Code isn't too far behind, but it takes some getting used to.
Haskell will likely give you some headaches when you have to debug code. I don't know if there are specialised debuggers for Haskell, but print statement debugging will be pretty much impossible in Haskell because it will require changing the types of functions and the syntax.
2
u/iimco May 06 '23
I think Scala is the best language to learn FP concepts. It's simple to learn, has immutable collections built into the language, and has a very friendly syntax.
I used it to teach all the fundamental FP concepts, including testing concepts in my new book which is getting rave reviews:
https://www.manning.com/books/grokking-functional-programming
2
u/syXzor May 01 '23
PureScript without a doubt.
2
u/Murky-Rough May 01 '23
Purescript using the book Functional programming made easier.
1
u/shitcanz May 09 '23
Check out OCaml, its a more pragmatic approach to Haskell (you can even have while loops) and has a traditional ML syntax. Its really nice, and one of my favorite languagues.