title: Typeclass dependency with tagless-final
body: <p>After watching John De Goes' "FP to the Max" (<a href="https://www.youtube.com/watch?v=sxudIMiOo68" rel="noreferrer">https://www.youtube.com/watch?v=sxudIMiOo68</a>) I'm wondering about approaches for writing FP programs in the tagless-final pattern.</p>
  
  <p>Say I have some typeclass for modelling a side-effecty thing (taking his <code>Console</code> example):</p>
  
  <pre class="lang-scala prettyprint-override"><code>trait Console[F[_]] {
    def putStrLn(str: String): F[Unit]
    def getStrLn: F[String]
  }
  </code></pre>
  
  <p>How would you depend on <code>Console</code>?</p>
  
  <h3>Implicitly</h3>
  
  <p>Like demonstrated in his video:</p>
  
  <pre class="lang-scala prettyprint-override"><code>def inputLength[F[_]: Functor: Console]: F[Int] =
    Console[F].getStrLn.map(_.length)
  </code></pre>
  
  <p><em>Pros</em>:  The function signature is clean, and you can benefit from typeclass automatic derivation</p>
  
  <h3>Explicitly</h3>
  
  <p>By passing the instance to the function directly:</p>
  
  <pre class="lang-scala prettyprint-override"><code>def inputLength[F[_]: Functor](console: Console[F]): F[Int] =
    console.getStrLn.map(_.length)
  </code></pre>
  
  <p><em>Pros:</em> This allows you to explicitly wire your dependencies according to your needs, and feels less "magical"</p>
  
  <p>Not sure what's the best / most idiomatic way to write this function, would appreciate your opinions.</p>
  
  <p>Thanks!</p>