i using poly1 shapeless build schemes of case classes(describing serialization) instances. build schema of
case class a(b: b, c: string, d: list[int], e: option[list[option[int]]]) there needs schema every contained type.
a schema object holds (besides other things) example value members. pull these example values instance primitive types (int, float, string, ...) schemes constructed on fly poly1. complex types (by mean custom types other member values) referenced instead, might have custom serialization methods well. solved requiring schema present in implicit scope.
now known how construct schema list (or other collection) iff there schema type parameter(s). same other monad-types option.
the idea of poly1 map member types schemes either constructed on fly or looked implicit scope. requires me define case primitive types necessary monads. approach works, has lot of boilerplate.
current poly1 object (ngschema trait schema[t] instances inherit, ref[t] looks instance of schema[t] implicit scope , functions integer, long , float construct schema[t] given example):
private object typerecursion extends poly1 { implicit val caseint = at[int] [ngschema](integer(_)) implicit val caselong = at[long] [ngschema](long(_)) implicit val casefloat = at[float] [ngschema](float(_)) ... implicit def caseoption[t: schema](implicit c: case.aux[t, ngschema]) = at[option[t]][ngschema]{ case some(v) => optionschema(typerecursion(v)(c)) case none => optionschema(ref[t]) } implicit def caselist[t: schema](implicit c: case.aux[t, ngschema]) = at[list[t]][ngschema]{ case v :: tl => seqschema(typerecursion(v)(c)) case nil => seqschema(ref[t]) } ... implicit def caseelse[t: schema] = at[t][ngschema]{ case _ => ref[t] } } this fails in case of member e because schema option[list[option[int]]] not present in implicit scope should constructed on fly. believe poly1 should recursive solve issue nicely. leaves problem option case need kind of type-bound inner type unknown @ point in recursion iff complex type cant constructed on fly.
i expect fuction map option[list[option[int]]] optionschema(seqschema(optionschema(integer(example)) while option[b] should lookup schema[b] implicit scope , execute optionschema(ref[b]).
is right approach problem?
the poly1 isn't implicit, cases implicit. think you're confusing typeclass level , value level. separate provision of implicit schema instances function operates on them (which can ordinary function?):
implicit object intschema extends ngschema[int]{ ... } implicit def optionschema[t: schema] = new schema[option[t]]{...} ... def myfunction[t: schema](t: t) = ... //or poly cases here if need it.
Comments
Post a Comment