Lifeless: limiting case class types

(NOTE: Shapeless split : attempt to restrict HList elements to their type and Shapeless: native HList restriction using Coproduct )

Question 3 - restrict case classes to parameter types

A very nice additional enhancement would be if I could use the HList constraints to restrict the case class only to create from AnyVals, Strings and a specific MyBaseTrait that recursively fulfill the same constraint. The restriction determined by the basic criterion and not related to any derived case class will be large. Sort of:

trait MyBaseTrait type MyCP = Boolean :+: Long :+: ... :+: String :+: MyBaseTrait case class ValidSimple(b: Boolean, s: String) extends MyBaseTrait case class ValidNested(s: String, vs: ValidSimple) extends MyBaseTrait case class NotOfBaseTrait(l: Long) case class InvalidNested(s: String, vs: NotOfBaseTrait) extends MyBaseTrait // => compile error 

This will fail much earlier. Is it possible? through Generic # Repr or DeepHList?

+2
source share

All Articles