by dnautics · 5y ago · 0 comments
There is some work being done towards better types for Erlang, as well as sharing types between languages on the BEAM. I'm excited to see what comes in future.
I have thought about this a lot (I'm writing a static typechecking library for Elixir) and really the problem is the dialyzer typesystem. Almost all of the problems stem from the root fact that there isn't a granular concept of how to treat functions in the type system. What does `(int, int) -> int` mean? Dialyzer does not have a good answer for that question.
Mind you I am not a "PL theory" type of guy, I do have a math degree, but my PhD is in the sciences, so I am more approaching this issue from a "discovering what would be truly useful" perspective more than "applying an existing typesystem to the BEAM", which is I think in line with the traditional pragmatism of the BEAM ecosystem.
This is an interesting question. Do you have any thoughts on what a better answer to that question might mean? Or languages you think do better here? Thank you
let's go with a simpler one: int -> int
"I guarantee that if you send me an int then i will return you an int without crashing"
In elixirland: `IO.inspect/1` would satisfy this, as would `Kernel.-/1`. The interesting thing is that `any -> int` is then a subtype of `int -> int` and we need a new type `_ -> int` which is "any one-arity function that emits int".
Then types become a statement of "resistance to crashing" in the BEAM vm, which I think is the useful thing that people are looking for.
I don't have answers to everything; I don't know how to deal with a function that generates random numbers from 1 to 20 and crashes on 13, for example.
We should have a discussion about this! I'll reach out on another channel.