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
Elixir v1.5.0-rc.1 has been released. This is the second release candidate for the upcoming Elixir v1.5. It includes bug fixes, enhancem...
New
josevalim
See the release notes: https://github.com/elixir-ecto/ecto/releases/tag/2.2.0-rc.0 To try it in your projects: {:ecto, "~> 2.2.0-rc",...
New
ericmj
A few months back we announced on the forum that we are adding support for private packages to Hex, today we are out of beta and going li...
New
josevalim
The goal of private modules is to define a module that cannot be trivially accessed by other modules where they are not visible to. In t...
New
Elixir
Release: https://github.com/elixir-lang/elixir/releases/tag/v1.9.1 1. Enhancements Mix [mix format] Print relative paths in --check-for...
New
Elixir
Release: Release v1.9.3 · elixir-lang/elixir · GitHub This release deprecates the use of URLs on mix archive.install, mix escript.instal...
New
Elixir
Official announcement: Elixir v1.16 released - The Elixir programming language 1. Enhancements EEx [EEx] Include relative file informat...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement