<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>