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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="tcoopman" data-post="58" data-topic="56827">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tcoopman/48/8112_2.png" class="avatar"> tcoopman:</div>
<blockquote>
<p>One solution to the discussion I’ve not seen yet is making errors/exceptions explicit in type expressions.</p>
</blockquote>
</aside>
<p>I’d throw my vote in for this level of being deliberate at the type level, so we can tell the compiler “hey, for this function please tell me that I’m not handling all my <code>case</code>s because when I refactor this in 10 months time I want to make sure that this one is updated correctly”.</p>
<p>And then for other functions where we’re ok with matching and throwing exceptions, like in <code>:ok = maybe_fail!()</code> or non-exhaustive <code>case</code>, we just tell the compiler to shush, we’ll handle it elsewhere.</p>
<p>This way we don’t need to add more syntax or new <code>case!</code> functions and move the responsibility of discussing the technical expectations of a function and deliberate documentation to the type system-level.</p>
<p>Heck, event throw some return type that says <code>AlwaysExhaustive</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294468" 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/type-system-updates-moving-from-research-into-development/56827/126">Post #125</a>
	                </div>
	            </div>
              <div id="likers-container-294468" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294468"
                     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 #125"></div>
  </section>
</div>
    <div class="postbit" id="294469" data-post-id="294469">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Wait, I just realised the implication is that the entire function must adhere to it, but then we can’t mix an exhaustive case and an <code>:ok = maybe_fail!()</code> in the same function. So I understand why we’re discussing all the other options. <img src="https://forum.elixirforum.com/images/emoji/apple/person_facepalming.png?v=15" title=":person_facepalming:" class="emoji" alt=":person_facepalming:" 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="294469" 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/type-system-updates-moving-from-research-into-development/56827/127">Post #126</a>
	                </div>
	            </div>
              <div id="likers-container-294469" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294469"
                     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 #126"></div>
  </section>
</div>
    <div class="postbit" id="294478" data-post-id="294478">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Some thoughts on the proposed <code>???</code> (which I <em>think</em> I quite like).</p>
<p>What if the meaning of this operator was: if the type checker can reach it, it’s an error/warning and shows the condition in which it could be reached. If the type checker can’t reach it, you’re good. If the execution ever <em>does</em> reach it at runtime (edit: without having issued a warning), it’s because there’s a bug in the type checker.</p>
<p>Consider:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def some_fun(:foo), do: :ok
def some_fun(:bar), do: :ok
def some_fun(:baz), do: ???
</code></pre>
<p>I might write this to indicate that <code>:baz</code> is a todo. If the type checker can’t find a situation where <code>:baz</code> is passed, you’re good. But when it sees these, you start getting a warning:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># obvious
some_fun(:baz)

# maybe less obvious, but this expr has type atom() which contains :baz
some_fun(String.to_atom("anything"))
</code></pre>
<p>Using these semantics, you could now use <code>???</code> wherever you want to be exhaustive:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case fun() do
  :foo -&gt; :ok
  :bar -&gt; :ok
  _ -&gt; ???
end

def some_fun(:foo), do: :ok
def some_fun(:bar), do: :ok
def some_fun(_), do: ???
</code></pre>
<p>This implies that, when you <em>don’t</em> use <code>???</code>, type checking can be “assertive” and assume that the return type of your case/function/etc. is narrowed to whatever you’re returning because it’ll error at runtime and be handled using existing mechanisms (OTP).</p>
<p>Another note: I do not think it should not be possible that a callee <em>require</em> that a caller handle an exception to successfully type check. E.g. a function that indicates some error type and requires that I call it in a <code>try</code> or something.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294478" 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/type-system-updates-moving-from-research-into-development/56827/128">Post #127</a>
	                </div>
	            </div>
              <div id="likers-container-294478" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294478"
                     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 #127"></div>
  </section>
</div>
    <div class="postbit" id="294516" data-post-id="294516">
  <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
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </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">
								<aside class="quote no-group" data-username="zachallaun" data-post="128" data-topic="56827">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/48/29208_2.png" class="avatar"> zachallaun:</div>
<blockquote>
<p>What if the meaning of this operator was: if the type checker can reach it, it’s an error/warning and shows the condition in which it could be reached.</p>
</blockquote>
</aside>
<p>The goal is rather to say: the type checker believes I need to handle this but I don’t expect this to ever happen (or, if it happens, I just want to crash).</p>
<p>In fact, if the type checker knows you can’t reach it, then you don’t need <code>???</code>. For example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case fun(some_input) do
  :foo -&gt; :ok
  :bar -&gt; :ok
  _ -&gt; ???
end
</code></pre>
<p>If the type checker knows only <code>:foo</code> or <code>:bar</code> is valid, then you can skip <code>_ -&gt; ???</code>, even if <code>:baz</code> could be returned for other inputs (but not the one you gave). The type checker could actually say that  <code>_ -&gt; ???</code> is not necessary. The only other scenario we could warn is if the <code>_ -&gt; ???</code> is the <em>only clause ever reached</em>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294516" 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/type-system-updates-moving-from-research-into-development/56827/129">Post #128</a>
	                </div>
	            </div>
              <div id="likers-container-294516" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294516"
                     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 #128"></div>
  </section>
</div>
    <div class="postbit" id="294518" data-post-id="294518">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="zachallaun" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/120/29208_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  zachallaun
                  </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="129" data-topic="56827">
<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>The goal is rather to say: the type checker believes I need to handle this but I don’t expect this to ever happen (or, if it happens, I just want to crash).</p>
</blockquote>
</aside>
<p>Okay, I understand the distinction now, I think. You’re satisfying the type checker by providing a catch-all <code>_</code> case and then indicating that you never expect it to get there at runtime and if it does, things should blow up.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294518" 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/type-system-updates-moving-from-research-into-development/56827/130">Post #129</a>
	                </div>
	            </div>
              <div id="likers-container-294518" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294518"
                     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 #129"></div>
  </section>
</div>
    <div class="postbit" id="294519" data-post-id="294519">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Tired: <code>???</code> / <code>unreachable?</code><br>
Wired: <code>wtf?</code> <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" 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="294519" data-batch-url="/posts/batch_likers">
                        6
                      </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/type-system-updates-moving-from-research-into-development/56827/131">Post #130</a>
	                </div>
	            </div>
              <div id="likers-container-294519" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294519"
                     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 #130"></div>
  </section>
</div>
    <div class="postbit" id="294532" data-post-id="294532">
  <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">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="129" data-topic="56827">
<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>
<pre data-code-wrap="elixir"><code class="lang-elixir">case fun(some_input) do
  :foo -&gt; :ok
  :bar -&gt; :ok
  _ -&gt; ???
end
</code></pre>
</blockquote>
</aside>
<p>This the kind of “defensive programming”  behaviour and  coding standards idioms that will be inadvertantly used to keep the compiler happy.</p>
<p>Coding for the happy path will be a thing of the past with more code and effort spent on the sad path for the same runtime behaviour of an exception/crash and the compiler now won’t even complain <em>because</em> it was deliberately silenced.</p>
<p>So how do we drive the right behavior? Ideally the above use of <code>???</code> should emit some compiler advice for the call sites that provide an input where the catch all <code>???</code> <em>could</em> be reached, but then we don’t need the catchall or <code>???</code> because the absence of the catchall is sufficient.</p>
<p>Depending on the nanny coding committee they may require catch all cases and logging something and/or raising an exception, but through their “defensive programming” practices they will miss out on learning about the call sites that pass bad inputs.</p>
<p>The stronger test would appear to be some kind of flag on the case match itself (not the body) perhaps  to say <em>I am handling this as an exception</em> and any <strong>root</strong> call sites that permit such value to flow here should be detected an error:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case fun(some_input) do
  :foo -&gt; :ok
  :bar -&gt; :ok
  !_ -&gt; raise "oops"
end
</code></pre>
<p>We want to identify the root causes where inputs are not curated, in preference to intermediate call sites to ensure the fix happens as close to a boundary layer as possible and minimise all the well intentioned nanny defensive coding, that can actually hurt detecting real problems and which is ultimately wasteful. This will keep in the spirit of coding the happy path whilst providing tight value semantics throughout the entire call graph.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294532" 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/type-system-updates-moving-from-research-into-development/56827/132">Post #131</a>
	                </div>
	            </div>
              <div id="likers-container-294532" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294532"
                     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 #131"></div>
  </section>
</div>
    <div class="postbit" id="294534" data-post-id="294534">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="adw632" data-post="132" data-topic="56827">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/9d8465/48.png" class="avatar"> adw632:</div>
<blockquote>
<p>This the kind of “defensive programming” behaviour and coding standards idioms that will be inadvertantly used to keep the compiler happy.</p>
<p>Coding for the happy path will be a thing of the past with more code and effort spent on the sad path for the same runtime behaviour of an exception/crash and the compiler now won’t even complain <em>because</em> it was deliberately silenced.</p>
</blockquote>
</aside>
<p>Hmm, I have literally the opposite take.</p>
<p>The above example isn’t defensive, it’s assertive. And while crashes may be a “sad path” in other languages, they’re not in Elixir: assuming you have process supervision set up correctly, it takes literally no extra code to handle a crash.</p>
<p>I could be very mistaken (and I have been about other things related to the proposed type system), but I do not believe the goal of the type system is to enable people to write <em>better code</em> than they’re writing now. Instead, it’s to help them get there faster and with a bit less occasional surprise.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294534" 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/type-system-updates-moving-from-research-into-development/56827/133">Post #132</a>
	                </div>
	            </div>
              <div id="likers-container-294534" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294534"
                     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 #132"></div>
  </section>
</div>
    <div class="postbit" id="294538" data-post-id="294538">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think I’m actually confused about the purpose of <code>???</code> now, but what you can you expect from a dynamic weenie?  <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p>
<p>I was thinking of cases (no pun intended) where you aren’t being exhaustive because the only the reason the catch-all case could ever be hit is if someone is messing with your runtime.  Of course there are the cases you don’t anticipate either (in which case <code>todo</code> is making more sense to me).  Am I way off?  Would anyone mind giving a concrete example or at least a scenario where <code>???</code> would be handy?  Or even point to some reading material?</p>
<aside class="quote no-group" data-username="adw632" data-post="132" data-topic="56827">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/9d8465/48.png" class="avatar"> adw632:</div>
<blockquote>
<p><em>I am handling this as an exception</em> and any <strong>root</strong> call sites that permit such value to flow here should be detected an error:</p>
</blockquote>
</aside>
<p>Isn’t this what <code>???</code> would do???  I think I’m totally confused, lol.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294538" 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/type-system-updates-moving-from-research-into-development/56827/134">Post #133</a>
	                </div>
	            </div>
              <div id="likers-container-294538" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294538"
                     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 #133"></div>
  </section>
</div>
    <div class="postbit" id="294539" data-post-id="294539">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I agree the new typing system / tool should make it easier to surface why do we get unexpected input deep in the call graph, yeah.</p>
<p>But I don’t think its intention is “make explicit what is now implicit”. IMO that’s a non-goal.</p>
<p>The true goal should probably be: show us a chain of function calls that pinpoints where exactly do our expectations and reality diverge, f.ex.:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule UserInput do
  def parse_and_validate_type_of_thing(text) do
    text = String.trim(text)

    value =
      cond do
        check_for_foo(text) -&gt; :foo
        check_for_bar(text) -&gt; :bar
        true -&gt; :invalid
      end

    ThingProcessor.do_stuff(value)
  end
end

defmodule ThingProcessor do
  def do_stuff(:foo), do: # ...
  def do_stuff(:bar), do: # ...
end
</code></pre>
<p>I would count the new system as a win if we could run i.e. <code>mix check</code> and get something like this in response:</p>
<pre><code class="lang-plaintext">Function ThingProcessor.do_stuff/1 will receive unexpected input because of:
  - UserInput.parse_and_validate_type_of_thing/1: could pass the value :invalid to it.
</code></pre>
<p>Not sure we even need any extra syntax in the language (at least for this scenario), though I’ll admit I would like to see Rust’s <code>unreachable!</code> implemented in Elixir in one form of another because it would be a perfect fit for the BEAM ecosystem where crashing on a bad assumption is actually a good thing and helps us gradually make our code bulletproof.</p>
<p>And if something <em>does</em> get added in Elixir I believe it would be an opt-in thing used only by those who need some more guarantees / preliminary checks.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="294539" 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/type-system-updates-moving-from-research-into-development/56827/135">Post #134</a>
	                </div>
	            </div>
              <div id="likers-container-294539" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="294539"
                     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 #134"></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/56827/load_more?page=14">Load more posts (34 remaining)</a>
</div></template></turbo-stream>