Fl4m3Ph03n1x
Learning Elixir, frst impressions ( plz don't kill me ! )
About me? ( if you have nothing better to do than reading about some random guy in the internet
)
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
- 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 forxis 1 and foryis 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:
- How does one use Monads in Elixir?
- Is it possible to use currying and partial application in Elixir using the function normal syntax, instead of the
.(x).(y)syntax? - Are there any libraries widely used and publicly available to for the use of currying and monads?
- Are there any libraries that improve upon the mistakes of the native API?
- 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.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 61 Posts!
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.
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
It does have list (or rather
Enumerable) comprehensions though, you use a range to generate consecutive values: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
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
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
Haskel Programmer:
Elixir Programmer:
kokolegorille
is kind of monad
There is also witchcraft
https://github.com/expede/witchcraft
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
Generally Erlang/Elixir uses pattern matching with a return value of
{:ok, data}or{:errror, error_message}and you just pattern match on thatLast Post!
mischov
Or you can just be like Clojure and add an additional
>to the end of pipe to indicate that you’re piping to the end!(P.S. Or this)