Asd

Asd

How do I make the new type system work?

Elixir 1.17 changelog states:

At the moment, Elixir developers will interact with set-theoretic types only through warnings found by the type system

I’ve compiled several old projects with Elixir 1.17 and OTP26 and I’ve found no warnings. I thought that I was doing something wrong and I’ve tried writing checking examples from the doc and still got no errors

$ elixir --version
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Elixir 1.17.1 (compiled with Erlang/OTP 26)
$ cat lib/xxx.ex
defmodule Xxx do

  # Performing structural comparisons between non-overlapping types, such as integer >= string

  def one(x) when is_binary(x) do
    if 1 >= x do
      1
    else
      2
    end
  end

  # Performing structural comparisons with structs, such as my_date < ~D[2010-04-17]

  def two(dt = %DateTime{}) do
    if two_compare(dt, DateTime.utc_now()) do
      1
    else
      2
    end
  end

  def two_compare(x, y) do
    x < y
  end

  # Accessing a key on a map or a struct that does not have the given key, such as user.adress

  def three(dt = %MapSet{}) do
    if three_get_field(dt) do
      1
    else
      2
    end
  end

  def three_get_field(x) do
    x.not_present_field
  end
end
$ mix compile --force --warnings-as-errors
Compiling 1 file (.ex)
Generated xxx app

Is there any compiler option I am missing or anything like this? How can I make new type system work?

First Post!

LostKobrakai

LostKobrakai

Where you get no warnings it’s not that you’re missing something, but the type system is not yet handling those cases. E.g. your Xxx.one(…) doesn’t cause a warning, but the following does:

x = "abc"
if 1 >= x do
  1
else
  2
end

Elixir 1.17 doesn’t suddently have a feature complete type system in the background, but it only started to integrate what a typesystem can do.

Where Next?

Popular in Questions Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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

We're in Beta

About us Mission Statement