title: How to abstract from Try in arrow-kt
body: <p>I'm using Arrow in my Kotlin backend project. I have repositories like this:</p>
  
  <pre><code>interface UserRepository {
    fun user(username: String): Try&lt;Option&lt;User&gt;&gt;
  }
  </code></pre>
  
  <p>Now I want to go step further and abstract from concrete <code>Try</code> type with returning <code>Kind&lt;F, Option&lt;User&gt;&gt;</code> instead. I was able to do it with this code:</p>
  
  <pre><code>interface UserRepository&lt;F&gt; {
    fun user(username: String): Kind&lt;F, Option&lt;User&gt;&gt;
  }
  
  class IdRepository : UserRepository&lt;ForId&gt; {
    fun user(username: String): Kind&lt;ForId&lt;Option&lt;User&gt;&gt;&gt; =
      if (username == "known") Id.just(Some(User()))
      else Id.just(None)
  }
  </code></pre>
  
  <p>But now I'm struggling to use it. I don't understand how we can say that the <code>F</code> in <code>userRepository</code> has to be a Monad, so that it can be used in monad comprehension block. Suppose I have some class defined like this:</p>
  
  <pre><code>class UserService&lt;F&gt;(ME: MonadError&lt;F, Throwable&gt;, repo: UserRepository&lt;F&gt;) 
    : MonadError&lt;F, Throwable&gt; by ME {
    fun someOperations(username: String) : Kind&lt;F, User&gt; = bindingCatch {
      val (user) = repo.user(username)
      user.fold({ /* create user */ }, { /* return user */ })
    }
  }
  </code></pre>
  
  <p>The compiler complains that it can't bind <code>user</code> on line <code>repo.user</code> as it requires the <code>Kind&lt;ForTry, ...&gt;</code> but the <code>repo.user</code> returns <code>Kind&lt;F, ...&gt;</code> which is unknown here. How to properly achieve abstraction from <code>Try</code> so that I can implement repositories with <code>Id</code> instances and how to use such repositories in service classes?</p>