title: Is there a type-class that checks for existence of at least one implicit of a type?
body: <p>I have a trait <code>Foo[T, U]</code> and a type-level algorithm that given an <code>L &lt;: HList</code> and a target type <code>U</code>, tells me whether there exists <code>T</code> in <code>L</code> such that there is an implicit <code>Foo[T, U]</code> in scope. This is implemented using the following type class: </p>
  
  <pre><code>trait Search[L &lt;: HList, U]
  
  object Search {
    def apply[L &lt;: HList, U](implicit s: Search[L, U]): U = null
  
    ...
  }
  </code></pre>
  
  <p>and we have the following: </p>
  
  <pre><code>object Test {
    type L = Int :: String :: HNil
  
    implicit val foo: Foo[String, Boolean] = null
  
    Search[L, Boolean] //compiles
  
    Search[L, Double] //does not compile
  }
  </code></pre>
  
  <p>What I would like is for the search to not take place at all if there is no <code>Foo[T, U]</code> for any <code>T</code> at all in scope, as then we already know that the algorithm will not complete. In other words, I want a type-class <code>trait Exists[F[_]]</code> for which instances exist if and only if there is at least one implicit <code>F</code> in scope, so the function <code>Search.apply</code> instead has signature: </p>
  
  <pre><code>def apply[L &lt;: HList, U](implicit ev: Exists[Foo[_, U]], s: Search[L, U]): U = null
  </code></pre>
  
  <p>In this case the compiler will only try to resolve <code>s</code> if there is any implicit <code>Foo</code> in scope. </p>
  
  <p>Is such a type-class possible to define? Does one already exist?</p>