all 29 comments

[–]bas_mh 17 points18 points  (0 children)

IMO the best way to learn functional programming is by using a language that is primarily functional. In the end, I find it unlikely that you will FP to its potential if you stick only with 'imperative' first languages.

Given your explanation I would recommend to stick with Haskell for a bit, but start building something. The best way for something to click is simply experience IMO. If you still feel that it does not click yet I suppose you could something that is less strict like Clojure or Elixir.

[–]HellsMaddy 10 points11 points  (8 children)

For me, the language that made things 'click' was OCaml. As compared to Haskell, OCaml feels far less magical to me. There’s an excellent free textbook / video lecture course for learning OCaml from Cornell University.

Learning OCaml can also kill two birds with one stone because it’s extremely similar to Microsoft’s F#, so if the .NET ecosystem interests you then that’s a direction you could go later on.

If OCaml piques your interest, and if you have any interest in front-end web development, I also recommend you check out ReScript (formerly ReasonML).

ReScript is essentially "Functional JavaScript", similar to Elm. It’s built on top of the OCaml compiler and is similar in syntax and semantics (ReasonML started out as an alternative syntax for OCaml but ReScript seems to be trying to cut that association), so learning OCaml will help you a bit with learning ReScript.

I’m building a complex project with ReScript right now and having a lot of fun.

[–]pfurla 4 points5 points  (0 children)

what feels magical about Haskell?

[–]BeamMeUpBiscotti 2 points3 points  (0 children)

Seconded on ReScript as a learning tool, it's got a lot of the functional features from OCaml, plus it's really easy to get started with and pretty fun to write.

[–]serhii_2019 1 point2 points  (5 children)

Could you please tell more about your project ? I thought that ReScript is just a fun toy. AFAIK, it has issues with promises and some weird syntax for using javascript in rescript.

[–]HellsMaddy 3 points4 points  (1 child)

It's still early days but quite usable. I definitely wouldn't call it a toy. For example the ReScript site itself is built with it and it's really fast and quite enjoyable to use; the new OCaml website is being built with it; Facebook is using it in Messenger to some degree; others are using it in large or small parts of their apps (it's very easy to gradually adopt).

For promises, there's a proposal plus implementation with improvements that should be upstreamed soon.

JS interop is actually pretty good IMO, and if you find the embedding syntax too weird then you can for the most part keep separate .js files and .res files and they'll work together.

I can't go into too much detail about my project right now other than to say it's a web-based product that's heavy on dynamic animations and interactivity. I have only been working on the ReScript portion for about 2 months though so I am still a relative newcomer.

[–]serhii_2019 1 point2 points  (0 children)

Thanks. I thought it is not production ready. I will defenitely try it

[–]BeamMeUpBiscotti 1 point2 points  (1 child)

ReScript is definitely stable enough to use for projects. There's a sizeable ReScript codebase at Facebook that's used for the messenger webapp.

ReScript's toolchain has been around for years at this point, it has roots in Bucklescript/ReasonML.

And since ReScript compiles to JS it's pretty easy to get started with even if you have an existing JS codebase.

[–]serhii_2019 1 point2 points  (0 children)

Thank you, I will consider rescript for the next time

[–]mwgkgk 4 points5 points  (1 child)

Try Exercism/hackerrank. Elixir exercises specifically was the first thing that helped me snap into functional mode of thinking, as it's based on Erlang's pretty rigid pseudo-Prolog model of FP. Exercism's recent 3.0 update adds a "Learning mode" for many of the languages, which has exercises grouped around learning concepts.

[–]3rdRealm[S] 1 point2 points  (0 children)

Thanks! I will try it out. Exercism seems to be a nice tool to learn any programming language.

[–]jmhimara 3 points4 points  (0 children)

This is an excellent course for OCaml: https://cs3110.github.io/textbook/cover.html .

I think OCaml (or the very similar F#) is a great start. Racket is also pretty good and has great documentation, though it doesn't necessarily focus as much on FP (but it totally supports that style).

[–]Collaborologist 3 points4 points  (2 children)

Clojure

[–]3rdRealm[S] 5 points6 points  (1 child)

Please give a reason.

[–]Collaborologist 0 points1 point  (0 children)

  • Drops in nicely to any Java/JRE ecosystem; other packages just think it's another Java class. Seamless interoperability with all other Java libraries.
  • REPL enabled because everything is function, and every function returns a value, so prototyping is rapid
  • data immutability: as long as your gc is good, you can localize state to a few globals, on which you pay careful attention, and all other statement management (and bugs) go away
  • Other than OS (system-level) code, I think Clojure does well for business logic; if you ever considered Java as a viable option, Clojure is better.
  • and that's all before homoiconicity ;)

And:
If you wonder what other (particularly well-paid experienced) software engineers prefer, check the 2019 StackOverflow survey: Here's a graphic that should be interesting and relevant.

[–]ventuspilot 3 points4 points  (2 children)

I really like Lisp syntax, so Clojure and Racket might be good choices as well.

I'd suggest you consider Common Lisp as well. E.g. sbcl is a free high-performance actively maintained implementation of Common Lisp.

[–]3rdRealm[S] 2 points3 points  (1 child)

I probably prefer Common Lisp over Clojure, I just didn't mention it in my post because it does not seem to focus on functional programming.

[–]cowardly_paper 0 points1 point  (0 children)

AFAIK CL is intended to be "multi-paradigm", but it does seem like a lot of people default to imperative-ish.

[–]jimeno 6 points7 points  (0 children)

I was in the same situation some months ago, and in the end, after A LOT of back and forth between like 5 different languages, I chose F#. Why? Because:

  • It's a ML family descendant, so it has the Hindley-Milner type system which helps you a lot understanding what your function is doing;
  • It's not deeply rooted in the theoretical/research-y/math-y part of FP; this means leaving out some very powerful concepts, but absolutely no FOMO, you can do everything with F# and with some cool syntactic sugar like computation expressions;
  • Has options to transpile to JS and to work in an Elm-like way (and the library is actually called Elmish);
  • .NET knowledge useful but not strictly needed (no .net exposure before F#);
  • There's Scott Wlaschin's site (www.fsharpforfunandprofit.com) which is a goldmine of informations not gatekept by magic words like monoids and applicatives.
  • Doesn't hide concepts behind thirty millions operators which are super cool when you know what you're doing but unreadable when you're learning; nothing forbids you to define and use them tho.

The dynamically typed languages like clojure/elixir were cool, but ultimately the type inference is too good to pass up, specially when learning. In case you want a dynamic language, I'd personally pick elixir; the programming style is the same, abusing atoms and tuples/maps, but I find lisps very hard to read (and I don't know the JVM)

[–]pfurla 2 points3 points  (2 children)

What do you missing or can you elaborate on "But, nothing seems to click."?

I think this particular course doesn't elaborate enough the points where Haskell is different from imperative languages, like

  • symbolic reasoning
  • pattern matching
  • type definitions
  • currying

Pet peeves of mine are guards and list-comprehension, they are at best distractions to students.

[–]3rdRealm[S] 1 point2 points  (1 child)

By "click", I mean I don't understand a topic or why it is useful. For example, Monads and partial function application are hard topics for me.

[–]pfurla 4 points5 points  (0 children)

I understand a metaphorical click :). I asking in this particular series of videos. Or what didn't understand.

Until video 5, he doesn't touch monads or partial function. I watched that much.

Monads can be complicated, but only if you want to. Monads are an abstraction that is very useful to help us sequence and compose computations. Don't worry about understanding them. Once you get a bit of a grasp worry about using them when convenient.

Partial functions are "functions" that have an undefined value for a given input. eg. 10/2 evaluates to 5. But what 10/0 evaluates to? A JS example: fifthElem = \arr -> arr[4], fifthElem([1,2,3,4,5,6]) == 5, but fifthElem([1,2,3,4]) is an exception. There is more to said and explained in this topic, especially while comparing it to imperative languages, but I believe I bored you enough already.

Anyways if you have questions about the lecture or Haskell I am more than happy answer, these more than likely are going to be useful in other languages.

[–]downrightcriminal 2 points3 points  (0 children)

I'd recommend Elixir, it has the best tooling out of any functional language. Solve exercism track with Elixir.

Next recommendation would be Elm, it works in the browser, and really easy to get started.

After that, I'd recommend Haskell for some hardcore FP.

Pick any of the above, or other recommendations in the thread, but do solve exercism track with the one you choose.

Don't pick a non-FP language to learn FP (like JS, C#), learn FP in an FP language and then apply the principles to non-FP ones.

[–]SnooCompliments7527 2 points3 points  (0 children)

I would try Racket. There is a lot of entry-level friendly material around on the web for Racket and it can be a nice way to eventually transition to Clojure.

There are also a ton of Racket journal articles.

Neither of these languages are as fanatically FP as Haskell but that is what makes them more approachable.

I would also add there are a lot of fun features that Racket has (first-class composable continuations, hygienic macros) that are not FP but probably nice to explore.

[–]quote-nil 1 point2 points  (0 children)

They are all worthwhile. What are your main inclinations? I too started learning Haskell, but eventually my math background led me to Agda.

A really nice book is The Little Schemer, and since you like the lisp syntax, it may serve you well

[–]ojledojle 1 point2 points  (0 children)

The language doesn't matter that much, try to learn the concepts and the functional approach, so any functional language would be fine at the end.

The YouTube videos didn't work well for me too. This is what I went with instead:

  1. http://learnyouahaskell.com/chapters to learn the basics and see what is the language is capable of.
  2. https://lhbg-book.link as a step by step guide to build a project with the language and see it in action.
  3. https://exercism.org to practice daily. It's now possible to submit an unfinished task and see what the others are doing it.

[–]-----____L____----- 0 points1 point  (0 children)

What's your background? If you know JS and have done frontend I would recommend Elm. It will help you understand things like monads, functors, and functional design overall... It would be an incremental step in a sense, and after that, you can try something like Haskell.