Fl4m3Ph03n1x

Fl4m3Ph03n1x

About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )

Hello all, this is my first post in this forum, so I apologize is something is off.
I am rather a direct person with strong opinions, but don’t be afraid of me, I don’t bite !

Recently I have been learning Elixir for a job offer ( yes, apparently you can find jobs using this thing! I mean, you have to sacrifice a virgin and a goat [ it can be a virgin goat ] to the Gods of Old and pray for 7 days, but hey, if it works it works right ? ) and I have been ramping up in my Elixir knowledge by watching as many conferences as possible.

I have a strong JS background where I do FP ( yes, it is possible ), and I got lured into this language becasue of it.

I have a lot of questions so I am giving this forum a chance!

Source

This 1 hour video covers the main aspects of Elixir and makes sure you have a lot of questions after. Suffice to say you won’t learn Elixir in 1 hour, but it is a good start I guess.

The following points summarize what I learned.

Elixir Facts

  • It has modules. Modules contain and organize functions, so it’s cool.
  • It has a ton of data types, most notably: Int, Float, String, Atom, Tuples ( arrays ), Lists, Dictionaries, etc.
  • Int type is not bounded. It has no maximum nor minimum value. If you ever had an overflow using Node ( like me ) you will really appreciate this feature.
  • Has a native pipe operator ! |> JS is being left behind :stuck_out_tongue:
  • Has native String concat operator <>
  • Has native List concat and diff operators ++`` and --
  • Has destructuring !
  • Functions can have the same name as long as their signature is different !
  • Has anonymous functions
  • Has no for loop constructor. WHHHATTATATAGGAHHAHAGATIhvgdjfsAVSGBZ
  • Creates child processes easily and sends messages between them easily as well

Elixir Cons

Not everything is nice with Elixir. It also has it’s technical shortcomings:

  • No partial application and no currying. This is something I would expect from a FP language ( like Haskell ) to natively support. Huge disappointment.
  • Currying and partial application via anonymous functions have a weird syntax. Yes, you can make a library to workaround this flaw, but the syntax you need to use is … weird at best: Function currying in Elixir
  • Being functional, Elixir has an horrible API. Most of it’s native functions are data first, instead of data last ( a basic concept of FP languages ).
  • No Monads. Again very disappointing.

Elixir Weirdness ( aka, stuff you will eventually get used to )

  • No return statements
  • Elixir also has default values for parameters, but the syntax is anything but intuitive. (x // 1, y // 2), this signature is saying that the default value for x is 1 and for y is 2. For most people, this would be a comment…
  • It has a short syntax for functions ( like the arrow syntax for JS functions ) but it is super cryptic.

Overall opinion

I know I am just starting. But aside from the data types ( that are immutable by nature ) JS actually has better support for the functional paradigm than Elixir. The native API ( String API comes to mind ) was designed using data first instead of data last ( a most basic flaw in an FP language ) and using currying with partial application feels clunky as all hell when compared to JS. And there are no Monads either … I mean Swift is not a FP language and even it has the Maybe Monad. How disappointing.

I must say I expected more from a newly designed FP language. The support for currying and partial application is rather atrocious but I can live with it.

I still didn’t get into error handling, but from what I have seen, it is extremely imperative with good old try rescue blocks. It would appear that basic knowledge from Promises and Futures is missing.

Questions

Or perhaps I am missing something? Allow me to rephrase my noob rant in an organized manner:

  1. How does one use Monads in Elixir?
  2. Is it possible to use currying and partial application in Elixir using the function normal syntax, instead of the .(x).(y) syntax?
  3. Are there any libraries widely used and publicly available to for the use of currying and monads?
  4. Are there any libraries that improve upon the mistakes of the native API?
  5. Is there a version of NPM or Ruby Gems for Elixir ( I understand there is none so far ) ?

Please let me know if I missed something. I have only seen a a couple of conference videos, I may very well be missing something brutal.

Showing Posts 1 to 10

dwahyudi

dwahyudi

You mistake Erlang and Elixir as ‘pure’ functional programming languages. They aren’t.

Erlang is not like Haskell.

Erlang was built in a business mindset to serve business goal which has to be achieved by making trade-offs. There are some aspects in functional programming paradigm that perfectly suites with business models they were after (reliability and concurrency). They took it, they used it, there you go, Erlang.

Haskell was built in an academic mindset to be used as academic purposes.

14
Post #1
NobbZ

NobbZ

In elixir everything is in a big-IO monad you can’t escape. Elixir is not a pure functional language, but uses side effects all over the place.

What do you mean by “normal syntax”? For me this looks pretty normal for calling into anonymous functions.

Searching on hex.pm for monads gave me a few results, but I’m unsure how widely used they are. Packages | Hex

Which mistakes do you mean? Is it only the subject first thing? Its not a mistake… Its designed to work with the pipe operator, not with function composition, as we do not compose as you’d do it in haskell.

I’m not pretty sure what you mean by this, but I think you are searching for hex-packages: hex.pm

Well, expected errors are usually handled via {:error, reason} tuples you match against.

Exceptions are usually only used for errors you do neither expect, nor could recover from.

mpraski

mpraski

It does have list (or rather Enumerable) comprehensions though, you use a range to generate consecutive values:

for i <- 1..n do
  ...
end
bulldog_in_the_dream

bulldog_in_the_dream

I don’t think Elixir ever aspired to be a “hardcore FP language” like Haskell or Purescript. It’s much more similar to e.g. Clojure (doesn’t have automatic currying either) than Haskell.

What Elixir loses in expressiveness and conveninece from not having some of the concepts you mention, it gains back in simplicity. That’s always a balance, and I like where Elixir falls on that scale.

chriseyre

chriseyre

The reason that promises and futures are missing from the language is that the equivalents are part of OTP library. To write large Elixir/Erlang will require you to understand OTP.

The libraries are very consistent and built with the pipe operator in mind.

Erlang grew out of practical business needs. It is functional because of those needs. There are very few languages that permit upgrading a system while it is still running (Erlang, Elixir and Smalltalk).

Have a look at exercism.io for some mentored exercises.

kokolegorille

kokolegorille

The real benefit of the language is not to be functional, but the ability to spawn million of processes, and still be able to supervise the system.

Because it was made for telecom.

DevotionGeo

DevotionGeo

Haskel Programmer:


Elixir Programmer:

15
Post #7
kokolegorille

kokolegorille

with

is kind of monad :slight_smile:

There is also witchcraft

https://github.com/expede/witchcraft

zkessin

zkessin

In general, if you are using try/rescue you are probably doing something wrong. Either pattern match or just let the process die and clean it up in the supervisor or somewhere else.

That is not to say you will never use them, they have their uses but in general don’t.

Erlang and Elixir look very different from Haskell This video that I did last year talks about this a bit

zkessin

zkessin

Generally Erlang/Elixir uses pattern matching with a return value of {:ok, data} or {:errror, error_message} and you just pattern match on that

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews