pmjoe

pmjoe

Where Elixir fits in the functional programming world?

I don’t want this thread to become a flamewar, but I was having some huge discussions with a few friends regards functional programming. First of all, my background is in imperative languages, I understand the benefits and value proposition of FP, but I don’t have a math background, nor the academic interest to learn all the bases and proofs of FP.

Do you see Elixir a “less qualified” FP language than something like Haskell? Looks like lately FP means having an effect system and being statically typed, which kinda of rules out most of the languages apart from Haskell and a handful others. Even languages like Scala and Ocaml have lots of escape valves and they can fall into a imperative approach and do effects anywhere without the compiler knowing it, so it’s best effort at the end of the day.

First Post!

D4no0

D4no0

While elixir and the underlying VM is inspired from functional languages, there are not many similarities to a language like haskell. I would say the prominent features that you see in a lot of functional languages that are also present in elixir are: functions as first class citizen, immutability, pattern matching.

Elixir/erlang, compared to haskell does not have a dedicated abstraction for managing side-effects. This means you can have impure functions that do side-effects, just as in any imperative language. The management of side-effects in elixir is very close to what golang does, treat errors as data and use those in your program flow. The way we usually do it in elixir is by wrapping the result/error in {:ok, result} or {:error, reason} tuples.

Scala never aimed to be a strictly functional language. The selling point of scala is that it contains features from all paradigms, such as classes, monads, mutability etc. It’s impossible to set strict compiler rules for a language that has a huge amount of features spanning across different ecosystems.

As a conclusion to make this more clear: Elixir has some features from FP, but the language and the VM it runs on is completely unique and does not fit into one single paradigm. Fault tolerance and distribution are its main unique strengths that are properties of the runtime and not the programming language.

Most Liked

gregvaughn

gregvaughn

I know the kinds of conversations and opinions you’re talking about. It’s important to realize that Haskell has come out of the academic community, and they’re exploring/implementing advanced computer science features. Elixir comes from Erlang, which was created to solve a business problem and focused on pragmatism (resilient systems even in the face of hardware failure) over purity. They have different goals and different language design tradeoffs, but they both treat functions as first class. I wish the academics had some other phrase besides “pure”/“purity” to distinguish their language goals, but then again I suspect that terminology helps them feel superior, so they have little motivation to change it.

jam

jam

IMO, elixir sits in the sweet spot. It’s what I see as FP-lite or pragmatic FP. I have a bias though to keep things simple and easy to reason about. “True” FP with monads and the like always struck me as prioritizing purity to the point where the code becomes difficult to grok. Perhaps there is a nirvana moment after spending substantial time with it.

100%

murrgelb

murrgelb

This is a very interesting discussion. We’ve seen effect-systems and immutability as characteristics (and even type systems - huh?).

I do 100% agree, that immutability is a differentiator for functional languages. However, what is also important is that functions are first-class. Passing functions as if they’re values and enabling higher order functions is the game-changer. This is what’s fundamental to implement different effect systems with ease. Monads? Sure just do it. Dependency injection? Free.

There are different ways to control side-effects. The trend in Haskell went from monad-transformers (which don’t compose) to free monads, to imitating an algebraic effect system. Man, the complexity. Scala did the same with catz and scalaz.

Elixir tends to be more pragmatic. What do we want to achieve? Is it for testing? Maybe use mocking or dependency injection? Is it for abstraction? Yeah, you can achieve 99% and implement composable abstraction without knowing category theory. We can do that, since we functions as first-class.

That said, I’d go with what @jam and @dimitarvp said: Elixir is a pragmatic functional programming language (as is e.g. clojure - no one will ever challenge clojure for not being functional).

Where Next?

Popular in Discussions Top

PragTob
Hey everyone, this has been on my mind for some time and I’d love your input on it! TLDR: I feel like maps are superioer for storing and...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20142 166
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

We're in Beta

About us Mission Statement