Scala doobie fragment with generic type parameter Scala doobie fragment with generic type parameter sql sql

Scala doobie fragment with generic type parameter

I'll go ahead an answer my own question, almost a year later. I never fully understood what was happening, and I have since updated to a newer version of doobie, so I am not sure how relevant this is. But now the documentation contains this clue:

Note: it is important to understand that Meta exists only to introduce Get/Put pairs into implicit scope. You should never demand Meta as evidence in user code: instead demand Get, Put, or both.

def foo[A: Meta](...)     // don't do thisdef foo[A: Get: Put](...) // ok

And indeed, between that change and the new version, this now compiles just fine for me:

class TableAccess[A: Get: Put](table: String) {

When the compiler is resolving implicit its searches for one of a specific type in the current scope. Here it seems like his finding more than one in his tree search.

It's not a matter of a missing typeclass or imports, it's more like you have too many of them and the compiler cant figure the right one.Try removing some implicit and see how that works or pass them explicitly.

One way I resolved this was to localize the type parameters (and their evidence) onto the method (on a static/companion object), and then it compiled.

Something like

object MinimalGood {  def good[A: Meta, B: Meta](a: A, b: B): Update0 =  sql"""$a $b""".update}