pepicrft

pepicrft

Set-theoretic types and compile-time types

Hi :wave:,

I upgraded to Elixir 1.18.0, and started getting type-checking warnings in the following module:

defmodule TestModule do
  @env Mix.env()

  def prod?() do
   @env == :prod
  end 
end

Because the types don’t match:

dynamic(:dev) == :prod

What’s a recommended way to tackle this scenario with the new set-theoretic types system in Elixir?

Most Liked

josevalim

josevalim

Creator of Elixir

We will fix this on Elixir v1.18.1 We will make it so it only warns when comparing across different types.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

In this particular case I would probably do it like this:

defmodule TestModule do
  if Mix.env() == :prod do
    def prod?(), do: true
  else
    def prod?(), do: false
  end
end

Last Post!

hq1

hq1

welp:

  defmacro always(term) do
    quote do
      :erlang.phash2(1, 1) == 0 && unquote(term)
    end
  end

  def prod?, do: always(unquote(Mix.env() == :prod))

Where Next?

Popular in Questions Top

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
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement