milessabin / shapeless

Generic programming for Scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Witness instance not available for HLists

hgrano opened this issue · comments

Apologies if this feature is already available, but I am not able to find it anywhere.

For the Witness type class I cannot find existing instances for HLists composed of types which have Witness instances. For example I think I should be able to resolve an implicit Witness.Aux[_0 :: _1 :: HNil].

If it's not available in the library then I'm happy to add it. The project I am working on is using shapeless 2.3.3.

I don't think we have it. I think it would be useful :-)

I've used shapeless before but never made any contributions to the library. The normal way I would think of doing this is you would have methods like the following defined in the Witness companion object:

implicit val witnessHNil: Witness.Aux[HNil] =
    new Witness {
      type T = HNil
      val value = HNil
    }

implicit def witnessHCons[H, L <: HList](implicit wh: Witness.Aux[H], wt: Lazy[Witness.Aux[L]]): Witness.Aux[H :: L] =
    new Witness {
      type T = H :: L
      val value = wh.value :: wt.value.value
    }

implicit def witnessGeneric[X, L <: HList](implicit gxl: Generic.Aux[X, L], wl: Witness.Aux[L]): Witness.Aux[X] =
    new Witness {
      type T = X
      val value = gxl.from(wl.value)
    }

But this won't work clearly because you derive the Witness instances using this macro So should I update the macro instead to be able to derive that a HList of singleton types is also a singleton type?

Witness is going away in favour of singleton types and ValueOf.
At this point it makes no sense to add more features to it.