another type mismatch.

29 views
Skip to first unread message

yves

unread,
May 13, 2013, 10:27:09 AM5/13/13
to scala...@googlegroups.com

 
trait Elt[Element <: Elt[Element,Ret],Ret] { self:Element=> }
 
trait EltBuilder[Element<:Elt[Element,Ret],Ret] {
  def apply(parent: Element, childBuilder: EltBuilder[Element,Ret]): Element
}
trait Motor[-Element<:Elt[_,Ret],Ret] {
  def onEnd(self: Element): Ret
}

class Core[R] {
  type Bld    = EltBuilder[Element,Ret]
  type Ret    = R
 
  trait Element extends Elt[Element,Ret] {
    val parent:Element
    val childBuilder:Bld
  }
 
  trait Mot extends Motor[Element,Ret] with Access {
    class Elt(val parent:Element, val childBuilder:Bld) extends Element {
      def onEnd(): Ret = Mot.this.onEnd(this)
    }
    val builder:Bld = new Bld {
      def apply(parent: Element, childBuilder:Bld) = new Elt(parent,childBuilder)
    }
  }
 
  trait Access {
    type Ret     = Core.this.Ret
    type Bld     = Core.this.Bld
    type Element = Core.this.Element
    /** To define! */
    type Elt<:Element
    def builder:Bld
  }


trait ExtCore[R] extends Core[R] {
  type Data
  def getData(parent:Element):Data
 
  trait Element extends super.Element {
    val data:Data
  }
 
  trait Mot extends super.Mot with Motor[Element,Ret] with Access {
    class Elt(parent:Element, childBuilder:Bld, val data:Data)
          extends super.Elt(parent,childBuilder) with ExtCore.this.Element

    override val builder:Bld = new Bld {
      def apply(parent: Element, childBuilder:Bld)  =
          new Elt(parent,childBuilder, getData(parent))

    }
  }
 
}

The line is red shows for the parent parameter:
type mismatch;
found : Mot.this.Element (which expands to) ExtCore.this.Element
required: ExtCore.this.Element


Elt is a generic element type
EltBuilder is a generic builder for Elt
Motor is a processor class for Elt

Core is a simple implementation, containing trait Mot with an almost full implementation
ExtCore is a refinement of Core, which adds some information to the basic Elt defined in Core.

For various reasons, it is difficult to impossible to change variances (i.e. Elt is not covariant)

I'm stuck on this.

Thanks.
Yves

Jan Vanek

unread,
May 19, 2013, 10:14:45 AM5/19/13
to yves, scala-user
Yves, you could look at the proposal about encoding of virtual classes in Scala. I found this link:
https://wiki.scala-lang.org/display/SIW/VirtualClasses
but there might be others. I believe understanding of the mechanism will clarify a lot of things for you.

Regards,
Jan
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

yves

unread,
May 19, 2013, 11:20:16 AM5/19/13
to scala...@googlegroups.com
An interesting link! Thanks!
It certainly is relevant to my problem.

Yves
Reply all
Reply to author
Forward
0 new messages