<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="301467" data-post-id="301467">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I don’t see how that changes anything. If we only have <code>integer()</code>, we won’t get any compile-time warning on <code>1/integer()</code>. There is no false positive here.</p>
<p><code>Tuple.duplicate/2</code> with a dynamic value can also only emit <code>tuple()</code>, we cannot assert on the shape. If you have specific shapes, then you need specific tuple instantiations. In the same way someone should not expect <code>String.to_atom(expr)</code> to return a particular atom instance at compile-time.</p>
<p>Edit: in any case, I am not saying we won’t have a false positive ever. What I am saying we will make decisions in order to guarantee the type system is performant and minimize false positives on common Elixir idioms.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301467" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/42">Post #41</a>
	                </div>
	            </div>
              <div id="likers-container-301467" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301467"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #41"></div>
  </section>
</div>
    <div class="postbit" id="301479" data-post-id="301479">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hst337" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hst337
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team quote-modified" data-username="josevalim" data-post="40" data-topic="58307">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<aside class="quote no-group" data-username="hst337" data-post="39" data-topic="58307">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/41988e/48.png" class="avatar"> hst337:</div>
<blockquote>
<p>Approaches suggested in <a href="https://www.irif.fr/~gc/papers/covcon-again.pdf" rel="noopener nofollow ugc">the paper</a> work only in certain cases.</p>
</blockquote>
</aside>
<p>Which cases? Can you please elaborate? Because the paper is about set-theoretic types and implementation of set-theoretic types, so I would be surprised if the suggestions listed there do not apply to the set-theoretic type system we are implementing.</p>
</blockquote>
</aside>
<p>They apply, but only partially. As the paper states, they use BDD of DNF (which is essentially a lookup tree for disjoint intersections) with lazy unions, and this structure has problems where non-union operations are applied to the set during the inference and subtype checking after a series of union operations.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301479" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/43">Post #42</a>
	                </div>
	            </div>
              <div id="likers-container-301479" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301479"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #42"></div>
  </section>
</div>
    <div class="postbit" id="301600" data-post-id="301600">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Rich_Morin" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Rich_Morin/120/2020_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Rich_Morin
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="26" data-topic="58307">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>On your side, what you could do is to write patterns and guards, which is idiomatic Elixir code anyway, and this will help the VM optimize code and the future type system to find bugs.</p>
</blockquote>
</aside>
<p>I would like to see some discussion of (current and/or impending) “idiomatic Elixir code” practices in the context of this work. For example, I’d think that writing lots of short functions (e.g., as recommended by <a class="mention" href="/u/pragdave" rel="nofollow">@pragdave</a>) would make things easier for the type inference code.</p>
<p>-r</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301600" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/44">Post #43</a>
	                </div>
	            </div>
              <div id="likers-container-301600" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301600"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #43"></div>
  </section>
</div>
    <div class="postbit" id="301604" data-post-id="301604">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It is literally writing patterns and guards. It can be in function heads, case, etc. The size of the function does not matter. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301604" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/45">Post #44</a>
	                </div>
	            </div>
              <div id="likers-container-301604" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301604"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #44"></div>
  </section>
</div>
    <div class="postbit" id="301606" data-post-id="301606">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Rich_Morin" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Rich_Morin/120/2020_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Rich_Morin
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Erm, imagine two implementations of some functionality. One uses a long, complex function chock full of flow control constructs (e.g., case, cond, if). The other has been decomposed into a set of small, tightly-focused functions which rely heavily on patterns and guards. Even if the compiler (etc) has no problem with the first approach, a coder might…</p>
<p>-r</p>
<p>P.S. Once again; great work!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301606" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/46">Post #45</a>
	                </div>
	            </div>
              <div id="likers-container-301606" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301606"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #45"></div>
  </section>
</div>
    <div class="postbit" id="301608" data-post-id="301608">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>To clarify, you asked in context of the work, so my reply focused only on that. In context of the type inference in my earlier quote, the size does not matter. <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301608" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/47">Post #46</a>
	                </div>
	            </div>
              <div id="likers-container-301608" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301608"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #46"></div>
  </section>
</div>
    <div class="postbit" id="301916" data-post-id="301916">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="DEvil0000" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/DEvil0000/120/31535_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  DEvil0000
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>How about a Number type so int and float can get expressed in one simple type.<br>
This may be useful for something like your negate/1 example.<br>
$ Number → Number</p>
<p>How about a template like T type so one could write “same in as out”<br>
$ T → T</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301916" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/48">Post #47</a>
	                </div>
	            </div>
              <div id="likers-container-301916" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301916"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #47"></div>
  </section>
</div>
    <div class="postbit" id="301930" data-post-id="301930">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sabiwara" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sabiwara/120/18612_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sabiwara
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Elixir Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="DEvil0000" data-post="48" data-topic="58307">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/devil0000/48/31535_2.png" class="avatar"> DEvil0000:</div>
<blockquote>
<p>How about a template like T type so one could write “same in as out”<br>
$ T → T</p>
</blockquote>
</aside>
<p>A possible syntax for this is covered in the recently published <a href="https://elixir-lang.org/blog/2023/09/20/strong-arrows-gradual-typing/" rel="nofollow">blog post</a>:</p>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">$ a and number() -&gt; a and number()
def identity(arg), do: arg
</code></pre>
<p>Or course, we can provide syntax sugar for those constraints:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">$ a -&gt; a when a: number()
def identity(arg), do: arg
</code></pre>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301930" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/49">Post #48</a>
	                </div>
	            </div>
              <div id="likers-container-301930" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301930"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #48"></div>
  </section>
</div>
    <div class="postbit" id="302172" data-post-id="302172">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adw632" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adw632
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s a really nice explanation in the blog post.</p>
<p>I understand  that no annotations are planned for the initial implementation of gradual types, however this did jump out as not ideal if annotations were supported:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">$ a -&gt; a when a: number()
def identity(arg) when is_number(arg), do: arg
</code></pre>
<p>Using both the guard and the annotation seems quite redundant, one of the reasons I don’t enjoy writing type specs and repeating myself.</p>
<p>Has there been any thought on how annotations and guards can replace one OR the other? (i.e. NOT both)</p>
<p>If for arguments sake we have the following annotation with no guard:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">$ a -&gt; a when a: number()
def identity(arg) do: arg
</code></pre>
<p>Could we expect the compiler to add the guard <code>when is_number(arg)</code> automatically?</p>
<p>Or turning this around taking annotations off the table completely where the complier respects guards and <em>only</em> the guards matter, would we still need another way to express return types?? Such as:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def identity(arg) returning number() when is_number(arg), do: arg
</code></pre>
<p>Or with different combinations of types:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def identity(arg)
      returning integer() when is_number(arg) or
      returning float() when is_float(arg) do: arg
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">def identity(arg)
      returning number() when is_number(arg) or when is_float(arg) do: arg
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">def somefunc(arg)
      returning ModuleA.t() when is_number(arg) or
      returning ModuleB.t() when is_float(arg) do: ....
</code></pre>
<p>Ideally multiple return clauses might be a signal to the developer to actually define specialized functions.</p>
<p>Just saying I would rather the compiler support directly expressing the return type as part of a function guard  if the compiler cannot infer the return type, than requiring repeat yourself annotations. Ideally I hope this is not required in the fullness of time and the compiler doesn’t need annotations or returning clauses at all not discounting the need for types on structs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="302172" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/50">Post #49</a>
	                </div>
	            </div>
              <div id="likers-container-302172" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="302172"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #49"></div>
  </section>
</div>
    <div class="postbit" id="302175" data-post-id="302175">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think a good chunk of the constraints applied here is that the typesystem is meant to be an optional piece on top of how people write elixir today – at best providing benefits to users without them needing to change anything/much to the code.</p>
<p>Elixir as it’s written today extensively uses multiple function heads to branch off functions based on input parameters. At least to me inline type annotation never made much sense in the context of multiple function heads. As an example there are commonly functions where you have converging codepaths of many possible inputs to a single output (<code>a | b | c -&gt; x</code>). You’d duplicate the result type if you put it on the function head.</p>
<p>I prefer the duplication of external type annotations for inputs – which are commonly in one place and therefore easy to find/read – to duplication of return values, which are scattered over potentially many lines of code with the function heads of the actual implementation of the function.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="302175" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/full-static-type-inference-of-set-theoretic-types/58307/51">Post #50</a>
	                </div>
	            </div>
              <div id="likers-container-302175" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="302175"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #50"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/58307/load_more?page=6">Load more posts (7 remaining)</a>
</div></template></turbo-stream>