Why doesn't scala infer the type members of an inherited trait? -


I have a group of types in which each has its own member:

  Seal Specialty Field Type {Type: Data Def Pars (String): Option [Data]} Object Name Extends Field Type {Type Data = String DRP Pars (in: string) = Some (in)} Object Field Field Type Expansion {type Data = Int def parse (in: string) = try {hold something (in.toInt)} {case_ = & gt; None}}  

and I have a group of types that operate on the set of FieldType s (using the boilerplate, the errata over reconnect ):

  Seal Attribute Schema {Type Schema & lt;: Product Type Data & lt;: Product Val Schema: Schema Df (in: Sec [String]): Option [Data ]} Extensions Schema Expands 1 Schema {Type D1 Type FT1 & Lt ;: Field Type} HE Government data D = 1} type schema = tuple 1 [FT 1] type data = tuple 1 [D1] def (in: Seek [string]) = Schema K_lkpars ((0)). Map (Tuple1.apply)} Specialty Schema 2 schema {type D1 type D2 type FT1 & lt;: field type {type data = D1} type FT2 & lt;: field type {type data = D2} type schema = ( FT1, FT2) type data = (D1, D2) def (in: sec [string]) = {to {f & lt; - Schema._1.parse (in (0)) S & lt; - schema._2.paras ((1))} produce (F, S)}}  

I thought I could use this system pretty well to set the set field Which are meaningful because Scala type members will be able to guess:

  class person extends Schema2 {val schema = (name, age)}  
< P> However, it does not compile! I have to include definitions for all types of members:

  class person schema 2 {type D1 = String; Type D2 = Int Type FT1 = Name.type; Type FT2 = era Type val schema = (name, age)}  

how can not estimate Scala D1, ... and FT1, ...? How can I refactor it, so I do not need to specify the type variable in the person ?

Note: Once I have a better understanding of the macros, I am planning to use them. Schema In addition, I did not want to use idle Great library, but I do not want to pull it out to solve a problem.

By declaring this:

  val schema: schema  

You specify that schema should be Schema or any of its subtypes therefore, the schema , you can not guess the schema because it's of schema.type .

You can solve your problem completely by reversing it: schema.type :

  Define typed alias schema schema 2 extends schema {type schema = (field type, field type) type FT1 = schema._1. type type FT2 = schema._2. type type D1 = FT1 # data type D2 = FT2 # data type data = (D1 , D2) def (in: Seq [string]) = {for {f & lt; - In schema._1.parse ((0)) & lt; - schema._2.parse (in (1))} produce (f, s)}}  

(Not sure that actually will work , But in theory it should be typed.)


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -