scala - Type inference error with multiple type parameters and Nothing -


i trying model adt representing properties, ability set default value.

so, type definition following, can pattern match on type:

trait propertytype[u] {   def typename: string }  case object oint32 extends propertytype[int] {   override def typename: string = "edm.int32" }  case object ostring extends propertytype[string] {   override def typename: string = "edm.string" } 

now, property parameterized propertytype parameter:

case class property[t <: propertytype[u], u](name: string,                                              propertytype: t,                                              nullable: boolean = true,                                              maxlength: option[integer] = none,                                              defaultvalue: option[u] = none) 

type inference works fine if both parameters present, i.e. following code compiles fine:

  val intprop = property("integer", propertytype = oint32, defaultvalue = some(123))   val stringprop = property("string", propertytype = ostring, defaultvalue = some("123")) 

also, prevents me trying set wrong default value specified type, following not compile.

val stringprop = property("string", propertytype = ostring, defaultvalue = some(123)) 

the issue i'm having inference if omit default value or set none, compilation fails type u cannot inferred:

val stringpropwithdefault = property("string", propertytype = ostring) //doesn't compile val stringpropwithdefault = property[ostring.type, string]("string", propertytype = ostring) //compiles 

can scala compiler infer type if 1 parameter present?

you don't use type t in examples, , getting rid of fix type inference issue:

case class property[u](name: string,                        propertytype: propertytype[u],                        nullable: boolean = true,                        maxlength: option[integer] = none,                        defaultvalue: option[u] = none) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -