pmjoe

pmjoe

How Elixir compares with Typelevel Scala?

I know a little of Elixir and apparently I’ll be moved to a Scala team at the company that I’m working by the end of the year. The codebase is pretty much Typelevel based and even having a little of knowledge of FP, from Elixir, that codebase is completely unreadable for me.

What I’m wondering is, Elixir is less functional than Typelevel Scala? Or this complexity is just the nature of a heavily statically typed FP language?

It’s astounding how simpler Elixir is compared to Typelevel Scala.

Most Liked

yawaramin

yawaramin

Interesting thread! I would say they have different philosophies.

Elixir/Erlang/BEAM philosophy is that runtime errors will happen and we have a robust framework in place to deal with them. But also it is nice to not lose productivity due to typos and other silly mistakes, so let’s add some level of simple typechecking support (at least for the time being, more in the future).

Typelevel Scala philosophy is that we can build our programs by plugging together small, ‘reasonably safe’ lego pieces of code and turning ‘effects’ into first-class values in our programs. Effect management is a very important part of this philosophy–primarily I/O, but also mutation, randomness, cancellation, etc. If we model each effect as a value (a description of what will happen at runtime), we can construct our programs as just different combinations of values–something programming languages are very good at.

Some people do argue that Elixir is less functional than Typelevel Scala because it doesn’t control effects. I don’t agree; I believe Elixir fulfills all the criteria (in my definition) to be a functional programming language. But I also think at a certain point arguing semantics is not that useful. One thing I will remind people is that all the ‘complexity’ may be seemingly overkill, but often we are not using raw Cats IO, we are using higher abstractions like fs2 streams. See eg Fs2

With a few lines of code, you can run streams that handle I/O, error-handling, cancellation handling, safe resource disposal, parallelization, retries, and many other abilities. You can of course do many similar things with Elixir, but due to the power of the type system, in Typelevel Scala code it’s often very plug-and-play:

The pattern of Network[F].server(address).map(handleClient).parJoin(maxConcurrentClients) is very common when working with server sockets.

code-shoily

code-shoily

Regardless of the flavour of Scala in question, in my opinion, Elixir (and Clojure and even ML cousins) are simpler than Scala.

With Typelevel Scala do you mean heavy usage of the Cat family of libs? If that then I’d say I had the same feeling. Other than Elixir I worked with Clojure and a little F# but I felt completely humbled when I saw some of those LoCs

Scala was (is?) my programming language for year 2024 and I wanted to get ahead of myself and start reading the Cats and the Red book but I got back to learning the basics as I didn’t quite get what they were coding on. I guess it’s the category theory influence that makes it appear tough?

I am tagging @yawaramin here since he is my go to person for all things Scala who also knows ways of Elixir. Maybe he can add some helpful info here.

Last Post!

D4no0

D4no0

The selling point of scala, at least in theory, is that it combines all features of OOP and functional programming. Before I found out about elixir, I found akka actors a extremely nice abstraction, as they are a copy of erlang processes.

I revisited the language about 6 months ago and I must say that I am not impressed, for example their implementation of monads as collections and usage of for comprehension in the way we use with in elixir is hacky to say at the very least.

I guess you would usually use scala when you have to interact with existing java code and want to make your project use some of the more advanced FP features, even though I would argue that Kotlin is a much better alternative these days, you have there finally a nice abstraction for concurrency and the syntax is much nicer, even if you don’t have more advanced FP features.

Where Next?

Popular in Discussions Top

restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
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
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement