<div dir="ltr">Thanks Tim, that reasoning makes sense.<br></div><br><div class="gmail_quote">On Sun, Mar 15, 2015 at 1:16 PM Tim Armstrong <<a href="mailto:tim.g.armstrong@gmail.com">tim.g.armstrong@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is only currently supported for external Tcl functions, btw, not regular Swift composite functions.<br><div><br>It's possible to do what you suggest - assume that any unknown types in the type signature are type variables.  It would be pretty straightforward to implement too.  The downside is that can lead to surprising behaviour from the user's perspective.<br><br></div><div>For example, suppose I declare a function with this type:<br><br></div><div>  f(Int x)<br><br></div><div>Int isn't the name of a type (the real integer type is int), so it would be inferred to be a type variable, and then you have a function that looks like it accepts ints, but actually accepts any input argument.<br><br></div><div>There are other scenarios too - e.g. if a type is defined in an imported module but you forget to import the module, suddenly you have a type variable where you thought you had a regular type.<br><br></div><div>I guess the way to think about it is that you're asking the programmer to add a little redundant information about their intent that then allows the compiler to check that their code is doing what they intended.<br></div></div><div dir="ltr"><div><br></div><div>- Tim<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 March 2015 at 18:51, Pete Vilter <span dir="ltr"><<a href="mailto:vilterp@uchicago.edu" target="_blank">vilterp@uchicago.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Tim,<br>This would be very nice to have in Swift/K — is there a proposal to add it? The syntax is similar to Java static methods; should be familiar to people coming from that background. One question (which applies to Java as well): why is it necessary to declare the type variables at the beginning of the line? Can't the compiler just see what variables are being used in the return and argument types?<div>Thanks,<br><div>—Pete</div></div></div><br><div class="gmail_quote"><div><div>On Fri, Mar 13, 2015 at 2:44 PM Tim Armstrong <<a href="mailto:tim.g.armstrong@gmail.com" target="_blank">tim.g.armstrong@gmail.com</a>> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Here's how I define contains in Swift/T:<br><div><br><span style="font-family:monospace,monospace"><K, V> (boolean o) contains(V A[K], K key)</span><br><br></div><div>K and V declares that K and V are type variables in the scope of the function definition.  I.e. when typechecking call to the function, K and V can be any type, so long as they match in all places.<br><br></div><div>The algorithm for typechecking is to match up input types to the argument types and bind the type variables, e.g. matching a string[int] array to V[K] would bind V=string and K=int, and matching int to K  would bind K=int.  If there isn't a consistent way to bind K and V, e.g. if one of the K's was a string, then typechecking fails.<br></div><div><br><br></div><div>For split, the function type would look like:<br></div><div><code></code>

<p><code><T, K> T[int][K] split(T[K], int n)</code></p><br></div><div>- Tim<br></div></div></div></div>
______________________________<u></u>_________________<br>
Swift-devel mailing list<br>
<a href="mailto:Swift-devel@ci.uchicago.edu" target="_blank">Swift-devel@ci.uchicago.edu</a><br>
<a href="https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel" target="_blank">https://lists.ci.uchicago.edu/<u></u>cgi-bin/mailman/listinfo/<u></u>swift-devel</a><br>
</blockquote></div>
</blockquote></div><br></div>
</blockquote></div>