Propagating implicit expansion for a formless LeftFolder

I am trying to solve this problem and want to reset HList

using a function Poly2

.

Here's a standalone MWE (you can copy it to the REPL with shapeless 2.0 to reproduce the problem)

import shapeless._; import shapeless.record._

case class RowParser[T](value: T)

sealed trait ColParser[T, K <: Symbol] { val column: Witness.Aux[K] }
case class Nullable[T, K <: Symbol](column: Witness.Aux[K], parserF: String => RowParser[T]) extends ColParser[T, K]
case class NonNullable[T, K <: Symbol](column: Witness.Aux[K], parserF: String => RowParser[T]) extends ColParser[T, K]

val cols = NonNullable('col1, (_ => RowParser(42))) :: Nullable('col2, (_ => RowParser("foo"))) :: HNil

object toRecord extends Poly2 {
  implicit def colParser[C, T, K <: Symbol, LL <: HList](
    implicit ev: C <:< ColParser[T,K]
  ) = at[Tuple2[List[Int], LL], C] {
    case ((vals, rec), x) => (vals, field[K](vals.headOption) :: rec)
  }
}

cols.foldLeft((List(1,2), HNil))(toRecord)
// expected: Some(1) :: Some(1) :: HNil

      

I am getting this error:

error: divergent implicit extension for type shapeless.ops.hlist.LeftFolder [shapeless. :: [NonNullable [Int, this.T], shapeless. :: [Nullable [String, this.T], shapeless.HNil]], ( List [Int], shapeless.HNil.type), toRecord.type]

starting from the hnilLeftFolder method in the LeftFolder object cols.foldLeft ((List (1,2), HNil)) (toRecord)

Thus, it is obvious that the compiler can find multiple implications to create needs LeftFolder

foldLeft

.

I can't figure out how to sort and explicitly tell the compiler what I really want to get LeftFolder

which is using toRecord

.

+3
scala shapeless


source to share


No one has answered this question yet

See similar questions:

6
Dynamically parameterize the Poly1 function in shapeless

or similar:

272
How to Use Shapeless in Quasiquote?
144
Shapeless Nat Limits
nine
How can I get the field name of a case class as a string / character at compile time using formless?
7
Highlight the Nth element of the HList of lists and return that value as an HList of values
3
Propagating Implicit Extension for a Type Class
3
Why / How to separate the type construction logic into different classes?
2
Extending implicit extension for shapeless.Typeable [...]
2
Another divergent implicit expansion
2
Seamless, not working in a generic context
0
Implicit implicit HList resolution without form - divergent implicit expansion



All Articles
Loading...
X
Show
Funny
Dev
Pics