r/functionalprogramming • • Nov 29 '21
Question I'm having a hard time with Haskell. What other functional programming languages is a few steps below it regarding accessibility (for a OO programmer)? I'm thinking about Elm...
At first, what caught my attention on Haskell was it is strongly imposed immutability and from there I learned about pure function. I eventually got really excited with its simple syntax and expressivity. However, after more than a month studying about it full time (I'm not working at the moment) it seems the possibility to create something minimally meaningful while knowning what I am doing seems really far away. I'm still struggling a lot with state and IO and basic concepts.
Maybe I'm just not really smart and I am okay with that.
My point is, I'm really excited with functional programming and would like to learn more, so I would like to take a look at other languages and would welcome suggestions.
I'm strongly inclined to Elm. According to wikipedia, its purely functional, all data are immutable and its syntax seems to be pretty much Haskell. I've seem some complaints about newer versions frequently breaking compatibility, but if this is the worst it could get I think I could get around that.Nevermind.
Few features that I would really like to see in it:
- strongly typed
- immutability on all data structures is encouraged or at least possible
- tail call optimization would be really great
- preferably not multi-paradigm
- decent community, library and documentation
Other language considerations:
I worked with JS for many years, but it is not strongly typed, its main functions has mutability everywhere, and its multi-paradigm. It seems that "JS is technically functional" is kinda a meme at this point, but I might be unfair for not knowing better about it.
I tried Clojure and actually liked it, although its polish notation still feels counter intuitive to me and the possibility to use other mutable Java libraries would make it every easy for me to do something bad (which includes Scala, Kotlin and Groovy).
I've seen some excitement with Elm, Erlang and Elixir, but didn't dig much deeper on these yet. Although multi-paradigm, saw same things with Rust.
People seem to like Ruby, but I don't much know about it.
Python does not have forced immutability.
Didn't seem much of F#, but seems to have a decent community.
19
u/gasche Nov 29 '21 edited Nov 29 '21
I would recommend OCaml, which is a functional programming language more on the "pragmatic" side than Haskell. (F# is a .NET variant of OCaml, the two languages are relatively close to each other.) OCaml is easier to learn, overall simpler; and it has the strong quality that it is easy to predict and reason about the performance of idiomatic code (something which is very hard with Haskell).
On the negative side:
(OCaml supports object-oriented programming if one wants to use it, but it is a rarely-used feature of the language. It is not "multi-paradigm" in the same sense that Scala that tries to blend the two styles.)
Elm has an interesting focus on user experience and some nice features, but it is not a general-purpose language, it is restricted to web development. I think that it's a good choice if you know that the web is your only focus, but maybe not otherwise.
4
u/[deleted] Nov 29 '21
I found this book really useful: https://mostly-adequate.gitbook.io/mostly-adequate-guide/ It’s aimed at javascript developers without any preliminary knowledge of FP and does a really good job at going through FP concepts step by step
4
u/milkyway-pirate Nov 29 '21
Don’t give up. We’ve all been there. Haskell IS hard to begin with.
If you want to learn Haskell. Do it, it will be very rewarding In the end - also for programming in other languages.
5
u/SickMoonDoe Nov 29 '21
You can't go wrong with LISP.
Common LISP has Objects and classes which will feel familiar
4
u/emarthinsen Nov 29 '21
I’d recommend Elm. I’ve studied other functional languages (and use some professionally now). Elm was the gateway to practical use for me. With all the others - Haskell, LISP, and Erlang specifically - it was a challenge to see how to build practical software with it. I knew it could be done, but I’d be half way through a book and it still wasn’t evident. It’s tough to stay motivated in that situation. Elm is different in that it is for creating web applications. The “hello world” of Elm is close enough to something useful that it’s easy to see how you would apply it. The syntax of the language is also pretty compact, so it doesn’t take that long to learn (in fairness, most FP languages have a compact syntax). And, despite Elm being a front-end language, it isn’t a toy language at all. It’s a powerful language and what you learn will be directly applicable to other FP languages.
16
u/ldf1111 Nov 29 '21
Scala 3 is very nice. It fixes most if not all of scala 2 issues. I would look into a library eco system called ZIO for functional effects also.
8
u/monks__cafe Nov 29 '21
Sometimes it can feel like you're not progressing even though you are, that being said my few thoughts (as someone experienced with Ruby, Elm, Scala, and a little Haskell) are:
7
u/snarkuzoid Nov 29 '21
Erlang is a pragmatic language that works really well in its intended domain: fault tolerant distributed systems. That's my go to for building systems like that, where I never ever want to receive a phone call at 4 am. I have an Erlang system that's been running for 2 decades, no phone calls yet.
Ocaml is a pragmatic language a little closer to the "pure" FP side. It's a great language for getting stuff done, and plays well with others. It generates blazingly fast code, but can also run as interpreted code, which allows for nicer debugging.
6
u/Aphova Nov 29 '21 edited Nov 29 '21
So here's my 2c FWIW.
Edit: please take the opinions below in terms of the context - I was also evaluating my first possible FP language for beginner friendliness as well as overall value for time invested.
TL;DR I strongly recommend trying F#, even though I'm still learning it. As I'm still learning it, take my opinion with a pinch of salt. For context, I'm a Ruby dev mostly with a fair bit of TS/JS, C# and some Go experience and I wanted to get into FP for similar reasons (typing, mutability issues, among others). So, I did the thing any rational lazy programmer would do and became an armchair expert in a few different languages (i.e. I watched YouTube and read blogs for a few weeks with a bit of tinkering on the side).
I passed on these languages:
The reasons I passed on those languages are largely the reasons I chose F#:
F# is about getting things done and getting them done right with a functional-first but pragmatic approach. The themes of F# according to its creator are for it to be "succinct, robust, performant" which I think is true but being modest. It's what happens when a language is designed with a laser focus on pragmatism and even a disdain for anything that isn't useful or practical. I believe it will tick all your boxes.
More than that, you seems to get your cake and eat it too:
As for not being multi-paradigm, F# is but I don't think that should be considered a drawback. If you go look at the language benchmarks game and look at the actual code samples you'll see that a lot of the fastest FP languages' code samples are written, well, not very functionally. There's mutation and loops and imperative stuff everywhere. Because imperative coding is generally still faster and more efficient than FP coding. I'd advise you to embrace functional coding as another tool, not a religion. Sometimes object-based code is appropriate and F# allows that, because F# is about getting things done, not breeding disciples of a purist pursuit. F# is multi-paradigm the same way JS/TS is functional. You can do it if you really want but you're going against the grain and it will guide you towards functional-first coding.
Here are the resources I recommend to get started:
P.S. Ruby is as functional as JS. Probably less so in fact. It's also smothered by the behemoth that Rails became - it's hard to find good Ruby code because most of it is Rails code or Rails-compatible code and if you're interested in FP you won't like it. It will always have a special place in my heart because of what it enabled me to do but I wouldn't recommend it in your case.
5
u/nevrome Nov 29 '21
Futhark helped me to get into the right mindset. It's a simple, functional language with similar syntax to Haskell. When I decided to go into Haskell more seriously, I first completed a small, fun Futhark project.
3
u/sminnee Nov 29 '21
I’d also recommend ReScript and F# as a frontend / backend pair. If you’re familiar with JavaScript, then starting with ReScript is a good bet - the semantics of the two are quite similar (they’re both OCaml derivatives), but the syntax of ReScript is likely to be more familiar.
3
u/[deleted] Nov 29 '21
Scala hits a sweet spot between going full java/oop with lot nicer syntax and good FP support to also be able to reach into proper full blown FP without caring much about oop. It has been usually a journey I've seen many people take over the years with starting into a most oop language and going up to more functional style step by step by learning and applying what they can and fits in their needs.
I've been personally trying to learn ocaml and sml but they syntax is hard many times because the language family is different. Scala keeps the familiar syntax one is more used in mainstream languages.
5
u/didibus Nov 29 '21 edited Nov 29 '21
I would recommend you try out Clojure.
For me in the beginning trying to learn Haskell I struggled with almost not understanding how to get anything done.
Clojure also has a bit of a steep learning curve, but allowing to be impure in some places, giving me a very interactive playground, and removing the static types which do add a whole other layer of difficulty, that did it for me. Its what allowed me to really begin to understand FP. I was then able to try Haskell again and things made sense now, and all that was left is learning the typed layer on top.
This also is a logical progression, since Lambda Calculus came first, and then Typed Lambda Calculus was added to it. So starting with just the Lambda Calculus is a good transition into the types variant of it.
Clojure will still force you into immutability, recursion, lazyness, function composition, higher order functions, using functions and closures as your primary units, etc. So it won't let you cheat out of those like I've found it possible to do in Scala.
That's my 2 cents.
2
u/stayclassytally Nov 29 '21
If youeve worked in JS ans used Redux at all, some of those concepts will trickle down nicely to functional programming.
2
u/StoneColdJane Nov 29 '21
Op, try Roc it's fully functional general purpose language direct descended of Elm.
2
u/nmarshall23 Nov 30 '21
Use Haskell to solve https://projecteuler.net problems.
You are not going to make anything amazing while learning FP.
Just start small, skip any problems that stump you. After you solve them in Haskell do them in another language.
2
u/BeamMeUpBiscotti Nov 30 '21
If you have a lot of JS experience, ReScript might be a good choice. Its syntax looks familiar to JS and it compiles to JS, but it has basically the same type system as OCaml and supports a lot of nice functional things like partial application, pattern matching, piping, and immutable data types.
2
u/CoreyTheGeek Nov 30 '21
I've enjoyed clojure personally, but I can guarantee it has nothing to do with you not being smart enough. Anyone can learn anything, we are all just different and need the lessons provided in certain ways
2
u/raxel42 Nov 30 '21
Scala may be a choice if you are from JVM world,
2
u/theearl99 Nov 30 '21
Try elm
2
u/depghc Dec 08 '21 edited Dec 08 '21
It's probably going to take more than a month to get comfortable in Haskell. There's a steep learning curve because of the FP concepts in Haskell are foreign to most imperative programmers.
"Haskell Programming from First Principles," https://haskellbook.com/, may be a good first step.
Obviously, not doing the exercises is the worst way to learn a programming language.
3
u/emarthinsen Nov 29 '21
One more thought. Elm checks all of your boxes. It’s single-paradigm, immutable, and strongly typed. It’s a very pure functional language. It’s almost mathematical. Another cool feature is that “null” doesn’t exist in it. I think that’s a big benefit.
Elm does share a lot of syntax with Haskell. In fact, the creator of Elm is a Haskell developer and the Elm compiler is written in Haskell. Syntactically though, I think Elm might more closely resemble F#.
One note on the Elm compiler is that the error messages are top-notch. They don’t just tell you something is wrong, but they tell you why it is wrong and hire to fix it. It’s very useful when you are learning.
1
u/ragnese Nov 29 '21
It sounds like the enforced purity and immutability are both appealing to you, and I agree that those two things are important for true functional programming. There are not many languages that exist today, IMO, that are strict in a particular paradigm. They're all trying to be "Jacks of all trades" and "take the best of every paradigm, blah blah blah."
I've never used Elm, and I frankly hate the entire JavaScript ecosystem, so I'm not sure how strict or awesome it is. There's also a project called PureScript that I don't know much about, but you might want to check out.
Elixir is kind of weird. It's definitely all about immutability, but I'm not sure I'd call it "functional" per se. It and Erlang are kind of their own thing. Elixir is a fantastically productive language, though.
Otherwise, Haskell is it. No other language is actually unashamedly functional.
There are several languages that are very conducive and optimized for functional programming, though. Clojure and Scala both come to mind, even though you mentioned the ability to use Java as a downside. But that's the best you're going to get, IMO. Just don't use Java. This isn't like an alcohol addiction- having Java nearby shouldn't be dangerous...
Rust is my favorite language, but definitely not functional (you acknowledged that it's "multi-paradigm", but I'd say that, like Elixir, idiomatic Rust is kind of its own thing. But it's definitely more imperative and OOP than FP).
0
u/[deleted] Nov 29 '21
[deleted] — view deleted comment
2
u/[deleted] Nov 30 '21
[removed] — view removed comment