title: Find type class instance for Shapeless HList in Scalaz state monad
body: <p>Say that I have a state monad with the state is an <code>HList</code> and I define a combinator that takes the first <code>n</code> elements of this <code>HList</code>:</p>
  
  <pre class="lang-scala prettyprint-override"><code>import scalaz._, Scalaz._
  import shapeless._,  ops.hlist._, Nat._
  
  def take[S &lt;: HList](n: Nat)(implicit tk: Take[S, n.N]):
      IndexedState[S, tk.Out, Unit] = ???
  
  for {
    _ &lt;- init[Int :: String :: HNil]
    _ &lt;- take(_1)
    x &lt;- state("abc")
  } yield x
  </code></pre>
  
  <p>The scala compiler gets stuck during type inference. It doesn't infer that the <code>S</code> type parameter of <code>take</code> is an <code>Int :: String :: HNil</code>. Thus, the compiler cannot find implicit value for parameter <code>tk</code>.</p>
  
  <pre><code>[error] could not find implicit value for parameter tk: shapeless.ops.hlist.Take[S,shapeless.Nat._1.N]
  [error]     _ &lt;- take(_1)
  </code></pre>
  
  <p>I know that I can help the compiler by simply exposing the state or by fixing <code>S</code>. But I don't want to! This extra-information seems redundant:</p>
  
  <pre class="lang-scala prettyprint-override"><code>def take[S &lt;: HList](hl: S, n: Nat)(implicit tk: Take[S, n.N]):
      IndexedState[S, tk.Out, Unit] = ???
  
  for {
    hl &lt;- init[Int :: String :: HNil]
    _  &lt;- take(hl, _1)          // Redundant
    _  &lt;- take[Int :: HNil](_1) // Redundant
    x  &lt;- state("abc")
  } yield x
  </code></pre>
  
  <p>Why in the first code snippet, scala compiler inferred <code>S</code> as <code>Nothing</code> instead of <code>Int :: String :: HNil</code>? I'm wondering if its possible to get this works without exposing the state or giving type information?</p>
  
  <p>Thanks in advance!</p>