News for hackers. Stuff that matters.
Re:Elixir 1.17 released: set-theoretic types in patterns, du... by tiffanyh on Wednesday June 12, 2024 @09:41AM (#40658058)
Does Gleam check types at compile-time?

And Elixir check types at run-time?

(If at run-time, would that mean it would slow down your entire app as a result?)

Re:Elixir 1.17 released: set-theoretic types in patterns, du... by bo0tzz on Wednesday June 12, 2024 @09:52AM (#40658166)
My understanding is that the BEAM vm already has some (optional) runtime typechecks in the form of guards, which this new typesystem will also add for you automatically. And that these guards are actually used to speed things up, for example by JITing more optimized code.
Re:Elixir 1.17 released: set-theoretic types in patterns, du... by throwawaymaths on Wednesday June 12, 2024 @07:06PM (#40664168)
So inserting those type checks automatically will cause regressions because those checks are not free at runtime, and there are cases where the JIT will look at the code and not bother optimizing.
Re:Elixir 1.17 released: set-theoretic types in patterns, du... by dub_gui on Thursday June 13, 2024 @03:38PM (#40673684)
To clarify, the type-checker does not modify compilation to the beam at all. Instead, it takes into account the predicted runtime checks to inject more static types into its analysis.

For instance, without even introducing annotations, if a function head has a guard `is_boolean(x)`, using the + operator on x within that function would lead to a type error.

Re:Elixir 1.17 released: set-theoretic types in patterns, du... by throwawaymaths on Thursday June 13, 2024 @05:52PM (#40675251)
exactly. The potential performance regression of guards is exactly why the elixir typechecker doesn't insert them. I guess I hadn't made that point clear in my comment. IIRC The elixir guides talks about excessive typechecking being a code smell.
Re:Elixir 1.17 released: set-theoretic types in patterns, du... by davydog187 on Wednesday June 12, 2024 @09:52AM (#40658170)
Both the Elixir and Gleam type systems run at compile time (and whenever you recompile during development)

There are no plans for runtime checking AFAIK

Re:Elixir 1.17 released: set-theoretic types in patterns, du... by arrowsmith on Wednesday June 12, 2024 @09:51AM (#40658157)
Elixir checks at compile time.