josevalim

josevalim

Creator of Elixir

Type system updates: moving from research into development

I hereby officially announce the Elixir type system effort is transitioning from research into development. Read the full-announcement here: Type system updates: moving from research into development - The Elixir programming language

This new exciting development stage is sponsored by Fresha (they are hiring!), Starfish* (they are hiring!), and Dashbit.

Thank you!

13367 164

First Post!

Eiji

Eiji

I understand the first 2 milestones, but can somebody say what’s a difference between the @spec attribute and 3rd milestone? :thinking:

The third milestone is to introduce the (most likely) $-prefixed type annotations for functions, with no or very limited type reconstruction: users can annotate their code with types, but any untyped parameter will be assumed to be of the dynamic() type. If successful, then we will effectively have introduced a type system into the language.

Can’t Elixir compiler use already existing specs instead of adding yet another annotation? We have any() and term() which should be more than enough as replacement for dynamic(). :question:

Also is adding a type system like in the post means replacing part or even all features of tools like dialyzer by Elixir compiler? If so I hope the compilation would not be longer because of creating plts … :sweat_smile:

Most Liked

josevalim

josevalim

Creator of Elixir

There are a few details I don’t appreciate about how we implemented typespecs (for example, I find them too verbose) but the deal breaker here is that typespecs are not capable of expressing the proposed type system, so we will need something new.

27
Post #7
lifeofdan

lifeofdan

I had to create an account here just to say how much I love this. This is incredibly exciting!

josevalim

josevalim

Creator of Elixir

The type system allows us to support any literal as type but it is still undecided if we want to do that. Opposite to the Dialyzer, an actual type system will be strict about the expected arguments. Imagine this code:

$ :foo or :bar -> string
def foo_or_bar(:foo), do: ...
def foo_or_bar(:bar), do: ...

Now imagine you call it like this:

foo_or_bar(String.to_existing_atom(string))

Because you are passing any atom to the function, the type system will warn about a type error. While Dialyzer would never warn. So you would need to write this instead:

case String.to_existing_atom(string) do
  :foo -> foo_or_bar(:foo)
  :bar -> foo_or_bar(:bar)
  _ -> raise "expected foo or bar"
end

Therefore, more specific types will require you to prove that you are passing those specific types and that may actually make the type system more annoying than helpful.

Since there are trade-offs here, it is a decision we will make later once we have a better feeling for the type system.

Correct.

Last Post!

erszcz

erszcz

This is quite a well-known wisdom in communities using languages with exhaustiveness checking. See Yaron Minsky’s talk “Effective ML” - he talks about catch-all patterns, exhaustiveness, and code evolution over time at 28 minutes into the video: Jane Street Blog - Effective ML video
BTW, this material is from 2010!

With a type checker a few more of the techniques he describes there would be possible in Elixir (or Erlang), or at least enforceable at compile time.

Where Next?

Popular in News Top

josevalim
Hello everyone, I would like to propose the addition of the Registry project to Elixir: https://github.com/elixir-lang/registry The Re...
New
josevalim
Hello everyone, Two vulnerabilities have been disclosed to Plug. Applications that provide file uploading functionality to a local files...
New
josevalim
Hi everyone, We have just released Elixir v1.8.0-rc.1. It contains only one bug fix compared to v1.8.0-rc.0. You can read the previous a...
New
josevalim
Announcement: Elixir v1.8 released - The Elixir programming language Release notes: Release v1.8.0 · elixir-lang/elixir · GitHub Thanks...
New
Elixir
This release adds basic support for Erlang/OTP 26. When migrating to Erlang/OTP 26, keep it mind it changes how maps are stored interna...
New
Elixir
Note this release includes offline Elixir installers for Windows per supported Erlang/OTP version. 1. Enhancements Elixir [Module] Mark...
New
Elixir
Elixir v1.18 is an impressive release with improvements across the two main efforts happening within the Elixir ecosystem right now: set-...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement