<p dir="auto">I was just messing around with some toy problems and discovered that you could create multiple methods with the same signature when using concrete types in parametric methods:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; foo(a::Int64, b::Int64) = a + b
foo (generic function with 1 method)

julia&gt; foo{T&lt;:Int64}(a::T, b::T) = a - b
foo (generic function with 2 methods)

julia&gt; foo{A&lt;:Int64,B&lt;:Int64}(a::A, b::B) = a * b
foo (generic function with 3 methods)

julia&gt; methods(foo)
#3 methods for generic function &quot;foo&quot;:
foo{T&lt;:Int64}(a::T, b::T) at none:1
foo{A&lt;:Int64,B&lt;:Int64}(a::A, b::B) at none:1
foo(a::Int64, b::Int64) at none:1"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-en">foo</span>(a<span class="pl-k">::</span><span class="pl-c1">Int64</span>, b<span class="pl-k">::</span><span class="pl-c1">Int64</span>) <span class="pl-k">=</span> a <span class="pl-k">+</span> b
foo (generic <span class="pl-k">function</span> with <span class="pl-c1">1</span> method)

julia<span class="pl-k">&gt;</span> <span class="pl-en">foo</span><span class="pl-c1">{T&lt;:Int64}</span>(a<span class="pl-k">::</span><span class="pl-c1">T</span>, b<span class="pl-k">::</span><span class="pl-c1">T</span>) <span class="pl-k">=</span> a <span class="pl-k">-</span> b
foo (generic <span class="pl-k">function</span> with <span class="pl-c1">2</span> methods)

julia<span class="pl-k">&gt;</span> <span class="pl-en">foo</span><span class="pl-c1">{A&lt;:Int64,B&lt;:Int64}</span>(a<span class="pl-k">::</span><span class="pl-c1">A</span>, b<span class="pl-k">::</span><span class="pl-c1">B</span>) <span class="pl-k">=</span> a <span class="pl-k">*</span> b
foo (generic <span class="pl-k">function</span> with <span class="pl-c1">3</span> methods)

julia<span class="pl-k">&gt;</span> <span class="pl-c1">methods</span>(foo)
<span class="pl-c"><span class="pl-c">#</span>3 methods for generic function "foo":</span>
<span class="pl-c1">foo</span><span class="pl-c1">{T&lt;:Int64}</span>(a<span class="pl-k">::</span><span class="pl-c1">T</span>, b<span class="pl-k">::</span><span class="pl-c1">T</span>) at none<span class="pl-k">:</span><span class="pl-c1">1</span>
<span class="pl-c1">foo</span><span class="pl-c1">{A&lt;:Int64,B&lt;:Int64}</span>(a<span class="pl-k">::</span><span class="pl-c1">A</span>, b<span class="pl-k">::</span><span class="pl-c1">B</span>) at none<span class="pl-k">:</span><span class="pl-c1">1</span>
<span class="pl-c1">foo</span>(a<span class="pl-k">::</span><span class="pl-c1">Int64</span>, b<span class="pl-k">::</span><span class="pl-c1">Int64</span>) at none<span class="pl-k">:</span><span class="pl-c1">1</span></pre></div>
<p dir="auto">If a parametric type variable uses a concrete type shouldn't that type replace the type variable in the signature?</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jakebolewski/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jakebolewski">@jakebolewski</a>, <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jiahao/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jiahao">@jiahao</a> and I have been thinking through some type system improvements and things are starting to materialize. I believe this will consist of:</p>
<ul dir="auto">
<li>Use <code class="notranslate">DataType</code> to implement tuple types, which will allow for more efficient tuples, and make tuple types less of a special case in various places. This might also open the door for user-defined covariant types in the future. (DONE)</li>
<li>Add <code class="notranslate">UnionAll</code> types around all uses of TypeVars. Each <code class="notranslate">UnionAll</code> will bind one TypeVar, and we will nest them to allow for triangular dispatch. So far we've experimented with just sticking TypeVars wherever, and it has not really worked. We don't have a great syntax for this yet, but for now will probably use <code class="notranslate">@UnionAll T&lt;:Int Array{T}</code>. These are mostly equivalent to existential types.</li>
<li>Unspecialized parametric types will actually be UnionAll types. For example <code class="notranslate">Complex</code> will be bound to <code class="notranslate">@UnionAll T&lt;:Real _Complex{T}</code> where <code class="notranslate">_Complex</code> is an internal type constructor.</li>
<li>Technically, <code class="notranslate">(Int,String)</code> could be a subtype of <code class="notranslate">@UnionAll T (T,T)</code> if <code class="notranslate">T</code> were <code class="notranslate">Union(Int,String)</code>, or <code class="notranslate">Any</code>. However dispatch doesn't work this way because it's not very useful. We effectively have a rule that if a method parameter <code class="notranslate">T</code> only appears in covariant position, it ranges over only concrete types. We should apply this rule explicitly by marking TypeVars as appropriate. So far this is the best way I can think of to model this behavior, but suggestions are sought.</li>
<li>TypeVars should only be compared by identity, and are not types themselves. We will not have syntax for introducing lone TypeVars; <code class="notranslate">@UnionAll</code> should suffice.</li>
</ul>
<p dir="auto">This is being prototyped in <code class="notranslate">examples/juliatypes.jl</code>. I hope this will fix most of the following issues:</p>
<p dir="auto">method lookup and sorting issues:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="48251774" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8959" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8959/hovercard" href="https://github.com/JuliaLang/julia/issues/8959">#8959</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="47931924" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8915" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8915/hovercard" href="https://github.com/JuliaLang/julia/issues/8915">#8915</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="35488206" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/7221" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/7221/hovercard" href="https://github.com/JuliaLang/julia/issues/7221">#7221</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="41309903" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8163" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8163/hovercard" href="https://github.com/JuliaLang/julia/issues/8163">#8163</a></p>
<p dir="auto">method ambiguity issues:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="45544896" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8652" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8652/hovercard" href="https://github.com/JuliaLang/julia/issues/8652">#8652</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="40533177" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8045" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8045/hovercard" href="https://github.com/JuliaLang/julia/issues/8045">#8045</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="30722042" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6383" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6383/hovercard" href="https://github.com/JuliaLang/julia/issues/6383">#6383</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="29564512" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6190" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6190/hovercard" href="https://github.com/JuliaLang/julia/issues/6190">#6190</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="29553275" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6187" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6187/hovercard" href="https://github.com/JuliaLang/julia/issues/6187">#6187</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="28717551" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6048" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6048/hovercard" href="https://github.com/JuliaLang/julia/issues/6048">#6048</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25982771" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/5460" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/5460/hovercard" href="https://github.com/JuliaLang/julia/issues/5460">#5460</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25496985" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/5384" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/5384/hovercard" href="https://github.com/JuliaLang/julia/issues/5384">#5384</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="13984573" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/3025" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/3025/hovercard" href="https://github.com/JuliaLang/julia/issues/3025">#3025</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="8801943" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/1631" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/1631/hovercard" href="https://github.com/JuliaLang/julia/issues/1631">#1631</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2410267" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/270" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/270/hovercard" href="https://github.com/JuliaLang/julia/issues/270">#270</a></p>
<p dir="auto">misc. type system:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="48007404" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8920" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8920/hovercard" href="https://github.com/JuliaLang/julia/issues/8920">#8920</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="45260829" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8625" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8625/hovercard" href="https://github.com/JuliaLang/julia/issues/8625">#8625</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="34342669" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6984" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6984/hovercard" href="https://github.com/JuliaLang/julia/issues/6984">#6984</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="32709131" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/6721" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/6721/hovercard" href="https://github.com/JuliaLang/julia/issues/6721">#6721</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="16852507" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/3738" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/3738/hovercard" href="https://github.com/JuliaLang/julia/issues/3738">#3738</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="11944347" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/2552" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/2552/hovercard" href="https://github.com/JuliaLang/julia/issues/2552">#2552</a> <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="43838745" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/8470" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/8470/hovercard" href="https://github.com/JuliaLang/julia/issues/8470">#8470</a></p>
<p dir="auto">In particular, type intersection needs to be trustworthy enough that we can remove the ambiguity warning and generate a runtime error instead.</p>