title: How do I call a generic Swift function when none of the arguments provides the generic type?
body: <p>The following compiles in the Swift REPL:</p>
  
  <pre><code>var m: [String:AnyObject] = [:]
  func f&lt;T: AnyObject&gt;(s: String) {
      m[s] = T.self
  }
  </code></pre>
  
  <p>However, if I naively try to invoke <code>f()</code>, thus:</p>
  
  <pre><code>let s: String = "foo"
  class Foo {}
  f&lt;Foo&gt;(s)
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>repl.swift:7:1: error: cannot explicitly specialize a generic function
  f&lt;Foo&gt;(s)
  ^
  repl.swift:7:2: note: while parsing this '&lt;' as a type parameter bracket
  f&lt;Foo&gt;(s)
   ^
  </code></pre>
  
  <p>If I try it without "explicitly specializing"...</p>
  
  <pre><code>f(s)
  </code></pre>
  
  <p>Swift decides I'm trying to do something even weirder, and I get:</p>
  
  <pre><code>repl.swift:7:1: error: cannot convert the expression's type 'String' to type '()'
  f(s)
  ^~~~
  </code></pre>
  
  <p>Meanwhile, however, if I define a new function <code>g()</code> as follows:</p>
  
  <pre><code>func g&lt;T: AnyObject&gt;(s: String, t: T) {
      m[s] = T.self
  }
  </code></pre>
  
  <p>and pass in a dummy <code>Foo</code> instance:</p>
  
  <pre><code>g(s, Foo())
  </code></pre>
  
  <p>it works fine:</p>
  
  <pre><code>&gt; m
  $R0: [String : AnyObject] = {
    [0] = {
      key = "foo"
      value = {
        instance_type = {}
      }
    }
  }
  </code></pre>
  
  <p>So is there a reason Swift lets me define <code>f()</code> in the first place? And once defined, is there any way to invoke it?</p>
  
  <hr>
  
  <p><strong>ETA:</strong> I'm aware it's also possible to define a function <code>h&lt;T: AnyObject&gt;(s: String, t: T.Type)</code> that takes the type explicitly. It's the fact that Swift allows me to define the implicit version that I find questionable.</p>