Sunday 15 June 2014

Is it possible to equal abstract type members in Scala? -



Is it possible to equal abstract type members in Scala? -

an advantage of generic type parameters on abstract type members seems former can equalled, example:

trait a[x] trait b[y] trait c[z] extends a[z] b[z]

similarly:

trait c[z] { self: a[z] b[z] => }

the assignment of type parameters says in fact 3 things: x = z, y = z, , hereby x = y.

the first case can represented analogously:

trait { type x } trait b { type y } class c extends b { type x = z; type y = z; type z }

however, sec case possible abstract type members? next solution won't work since type "z" cannot referred self-type definition, must come first:

trait c { self: b { type x = z; type y = z } => type z }

strangely, next seems compile if type requirement of "b" violated:

trait c2 { val a: { type x = z } val b: b { type y = z } type z } class a2 extends { type x = int } class b2 extends b { type y = string } class d extends c2 { override val = new a2 override val b = new b2 type z = int }

you can utilize witness type parameters equal, either =:= or scalaz.leibniz.=== (which more general, means depending on scalaz).

class c extends b { type z; val w1: x =:= z; val w2: y =:= z }

then there no way instantiate if types not equal, , can utilize w1 , w2 "convert" values of type x or y type z.

scala types abstract

No comments:

Post a Comment