scala - How to load implicit Manifest from polymorphic type field -


i trying build interpreter adt don't know how solve problem of loading implicit manifests in nice way

sealed trait polymorphic[t] case class type1[t: manifest](field1: t) extends polymorphic[t] case class type2[t: manifest, v: manifest](field1: t, field2:v) extends polymorphic[t] {     def vmanifest: manifest[v] = manifest[v] }  object interpreter {     def eval[t: manifest](polymorphic: polymorphic[t]): t = {       polymorphic match {         case type1(field) =>           ???         case value: type2[t, _] =>           implicit val vmanifest = value.vmanifest           evaltype2(value)       }     }      def evaltype2[t:manifest, v:manifest](type2: type2[t,v]): t = ??? } 

this best solution create don't had create vmanifest function able load manifest in eval.

is there better way this?

remember t: manifest shorthand way write implicit constructor argument. if want make argument visible outside, make val:

case class type1[t](field1: t)(implicit val tmanifest: manifest[t]) extends polymorphic[t] case class type2[t](field1: t, field2: v)(implicit val tmanifest: manifest[t], val vmanifest: manifest[v]) extends polymorphic[t] 

(and these days, want classtag or typetag rather manifest).


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -