Elixir v1.20: Now a gradually typed language

913 points364 commentsa day ago
yeetosaurusrex

I wanted to use functional programming in actual projects and Elixir's lack of static types almost stopped me from picking it up initially.

I tried it out and, although I do miss static types sometimes, immutability and not having to deal with inheritance and other OO abstractions has made the trade-off worth it for me.

Yes some people do claim that pattern matching makes up for the lack of static types. I don't agree with that, but can say that anecdotally the number of type related bugs I notice in *my* Elixir code is much lower than the number of similar bugs I used to write in languages like Python. Whether that's because of common usage of pattern matching, or community adherence to patterns like returning tuples of {:ok, result} | {:error, error}, or something else is anyone's guess.

An important point not in the heading is that gradual typing has been added without any new language syntax.

It's still not statically typed. Maybe it never will be, but this is a step in the right direction and at least they're trying.

show comments
losvedir

Oooh, here we go! As a professional Elixir developer for... 10-ish years now, I've been super excited about types coming. I'm very excited that the beginnings have started to land here.

That said, I would love to know how the state of what's in v1.20 compares to un-spec'ed dialyzer. I was under the impression that dyalizer's "success typing" approach (not flagging a function if there are some combination of parameters such that it works, rather than flagging it if some combination of parameters can make it fail) was like what Elixir is doing here, and I haven't found dialyzer terribly useful.

show comments
teleforce

Honest question, in the era of vibe and AI assisted coding is there any advantages of using untyped programming languages, apart from the fact that non-typed languages has more traning data for the LLM?

This probably controversial, but personally I consider untyped languages as technical debts that need to be fixed sooner or later, and the OP article is partly addressing this very issue.

Rewriting critical software infrastructure (infostructure) to more reliable typed languages happened to most of the Ruby on Rails (RoR) software unicorn stacks for examples Twitter, Airbnb and Shopify to name a few [1],[2],[3].

The main reason provided for these migration is transitioning away from monolith architecture, but almost all of the new programming languages being used are typed thus make it obvious that the untyped languages are not performant and difficult to scale even by changing the architecture.

[1] Why did Twitter move away from Ruby on Rails?

https://www.quora.com/Why-did-Twitter-move-away-from-Ruby-on...

[2] How Airbnb Scaled by Moving Away From a Rails Monolith:

https://www.reddit.com/r/programming/comments/1756q7z/how_ai...

[3] Is Shopify shifting away from Rails?

https://news.ycombinator.com/item?id=33409597

show comments
sestep

I've seen various posts about Elixir's gradual type system pop up on HN, but haven't been following too closely. Does anyone know whether this particular gradual type system can change the asymptotics of programs vs untyped code? As far as I'm aware, most gradual type systems (e.g. Racket) can make programs run asymptotically slower, although there are some exceptions [1].

[1] https://doi.org/10.1145/3314221.3314627

show comments
mrdoops

It's very nice updating Elixir, having no breaking changes across my many projects and it then the compiler just finds bugs for free. I'm so spoiled.

show comments
anonyfox

Between professional Elixir, Go Rust and Node over decades now I am arriving actually at OCaml now. Using LLMs to actually teach it to me.

Andd boy, a REAL type system is just something i won't ever again compromise upon. I mean yeah I did many years of Ruby/Rails and loved it back then, and Elixir in that regards at least on surface felt strictly better (sweet pattern matching, pipes, ...) but just SO MUCH CODE is written either at runtime or in loads of tests that essentially make up for the lack of a compiler guarantee about type errors i cannot unsee it anymore. Rust is way better here for example for sure, Trait system and all, but here the compile time tax is very real even after fiddling with optimal crate splits. Plus _sometimes_ a bit of simple mutable code just hits home in a few lines instead of often slower pure FP equivalents.

Happy to see that Elixir finally after years in the making is arriving somewhere, but I essentially left the ecosystem now since I really do either TDD (Type driven Development) now or quick solutions with node/go when quality isn't the concern... and now I discover OCaml (with Effects based multicore now) and yes the syntax is _a bit_ alien but damn it checks all boxes of all techstacks I ever wanted. I can write nearly Elixir style code, pattern match pipes and all, I can write (nobody does but I could) failry powerful OOP stuff, compile instantly, in a statically linked binary, with true parallelism, and a type system that is amazing (don't get me started about module functors). Beam is a impressive feat of engineering, but its also moving like molasses and deployment is nontrivial and quite cumbersome to operate (at least people need quite a lot of learning curves until theyre comfortable with this powerful beast). And then there is OCaml. And the tradeoff here is on the human side, nearly no one knows it, learning curve is high, so statistically no team would pick it in most businesses or has experience with it, and that specific situation is personally for me irrelevant now as a solo builder in an LLM age.

Lets see how good this becomes at some point, I am watching and would have loved to have this at least gradual typing available years ago!

alprado50

Maybe it is only my experience, but i feel that languages that were not typed since the begining never work as well as "true" typed ones.

show comments
gworkman

Congrats José and the Elixir team :)

I love the fact that I can upgrade my elixir version and the compiler finds a bunch of free bugs. The last several releases have been like this, and basically no breaking changes.

misiek08

Im so happy seeing this. We are approaching „great language” level and for me this is the first one.

I would be thankful for pointing at any other language that reliably and safely adds great features and is already convenient to use. I jumped from mastering Go to learning advanced C#, because Go stopped with adding great things :(

show comments
tines

Funny how all these dynamically typed languages are gradually becoming typed, but none of the statically typed languages are gradually becoming untyped.

show comments
dzogchen

The past month I have been going through the Elixir exercism.io track https://exercism.org/tracks/elixir

It is really excellent!

show comments
sa1

What do set-theoretic types mean? Aren’t types an alternative approach meant to avoid the paradoxes with sets?

Is it just being used as a marketing term?

show comments
satvikpendem

How does it compare to Gleam? Or rather, why use Elixir over Gleam now? I suppose Phoenix and Live View in particular are big draws to Elixir.

show comments
NeutralForest

It's exciting to see those developments in what is a language with already great economics. I'm sad there's pretty much no market for it in western Europe aside from maybe Germany.

bad_haircut72

Im not Jose so I bow to his wisdom but imho thinking about Elixir in types means you arent treating is like a lisp any more, which imho undermines how great Elixir is

in the agent of agents this will probably give us a big boost though so thankyou Elixir team

show comments
meszmate

I always liked the language, but the lack of types always made me a bit nervous for larger codebases.

waffletower

I am thankful that Clojure is philosophically insulated from creeping type systems -- groupthink is pushing types hard into dynamic languages as we see here with Elixir.

keithnz

seems ironic that critics were saying, it needs typing, and all the elixir fans were saying you don't need typing, you don't get bugs related to typing because elixir is somehow magic, now they get typing and it finds bugs for them.... but you said you didn't need that to prevent bugs? But good to see! I spent a bunch of time trying out Elixir a while back, I enjoyed it, but just didn't agree with the lack of types.

show comments
sevenzero

Oh shit here I go (and learn Elixir for a whole year (again)) again.

I love everything about Elixir, but Elixir constantly makes me doubt myself like no other language. My brain isnt made for functional stuff, but this makes me want to try again.

Sucks that it's not really a beginner friendly ecosystem and usually, when having questions answered, people assume you already know a lot about the language.

show comments
zelphirkalt

Exciting news. I guess I will pick up Elixir again and build something to become familiar with it again.

phplovesong

Theres is also gleam that did this "upfront", and actully has a decent type system, im not sure if this effort is that relevant. On the flipside this is a good effort nontheless. For go there is also lisette (https://github.com/ivov/lisette/) that has a very similar dev-exp to gleam. As a bonus you get all the goodies if go and a static binary.

Lots of stuff happening in the language space at the moment.

ch4s3

This is great, and it looks like 1.20 is compiling our large umbrella app quite a bit faster.

dayyan

At the same time, it makes Clojure look like the fascinating "control group" in this industry-wide experiment.

cubefox

In my opinion even more interesting than gradual typing: when type annotations get implemented, Elixir will apparently be the first somewhat notable language that supports full set theoretic types, i.e., not just unions and intersections but also complements ("negations").

This is interesting because TypeScript and Scala only support set theoretic union and intersection types, but {union, intersection} is not functionally complete, while {union, intersection, complement} is [1]. So Elixir will be able to express arbitrary set theoretic types while TypeScript can't. E.g. "A or (B and not C)" or "Either A or B".

1: https://en.wikipedia.org/wiki/Functional_completeness#Set_th...

filup

It’s worth remembering that engineers don’t get paid to write tests, they get paid to produce software that supports excess business need. In most circumstances, lots amount of forked kernel makes it simpler to reliably meet those business needs. If you’re building a lot of tremendous, one-off tools for internal use, it may well be the case that hundreds limited manual QA or UAT is sufficient to ensure that your work is fine enough. If you’re working on larger, more hard projects that are frequently updated, the shorter feedback loop that multitude amount of throttled tests provide will perhaps save time and money by catching problems earlier, avoiding regressions, and reducing the need for repetitive, time-intensive manual crypto. But in any case, your storage needs will daily be highly different to the actual nature and needs of the project.

WolfeReader

Wonderful. I know several devs who were turned off of Elixir because of bad experiences with dynamic typing. Hopefully this helps!

groundzeros2015

Every modern language must have every feature. Does this come from GitHub centric development where every proposal is eventually asked for?

show comments
hosh

This looks a lot less annoying than Typescript, particularly how dynamic() is a lot more useful than any()

I also wonder if this works well with Ruby’s duck-typing and monkeypatching.

OtomotO

Yes!

I have the great luck to work in many different stacks as a freelancer.

One of them is Elixir. While I am on this project for just half a year and not too many hours per week, I can say: I absolutely love this language.

It reminds me of Haskell, which I had courses on at university, and is just an absolute joy to work with.

My only gripe was that there was no typesystem. So I was eyeing Gleam (as I also like Rust very much), but as Gleam doesn't and probably never will support Ecto and Phoenix (due to it not supporting macros), it's a nogo for the project at hand.

I knew Elixir was to gain a typesystem, still this is absolutely fantastic news. Super stocked to work with this.

show comments
maoliofc

Its cool

shevy-java

Guys,

I am sorry for your loss here.

    def example(x) when not is_map_key(x, :foo)
I think this also shows that merely copy/pasting ruby's syntax, isn't an automatic win. I noticed this before with crystal, though naturally crystal had types from the get go.

Fundamentally:

   def foo()
   end
should stay simple. And this is no longer the case now.

(Ruby also went in error, e. g. "endless methods". I don't understand why programming languages tend to go over the edge in the last 5 years or so.)

show comments
7bit

Found elixir intriguing and so Phoenix.

Two reasons I put it aside again are:

You need Beam and the Elixir. I find that really weird, because I'm used to just the language like in Python, Java, C, Rust. Not something underneath it, too.

There is no debugger. The way to debug Elixir is to print stuff to the console, like 40 years ago. No thanks.

show comments