Type problem

View: New views
4 Messages — Rating Filter:   Alert me  

Type problem

by Naftoli Gugenheim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Correction: only A is library (it's really lift's Mapper) and B is a base for several A's. C is a trait that operates on an A, which we want to instantiate so that it should operate on various B derivatives.

-------------------------------------
Naftoli Gugenhem<naftoligug@...> wrote:

trait A[T <: A[T]]
trait B[T < B[T]] extends A[T]

trait C[T <: A[T]]
A and B are library defined.
How can I instantiate a C?

Parent Message unknown Re: Type problem

by Naftoli Gugenheim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, I didn't ask the question right. I need an instance of C that can handle any instance of any subclass of B.

-------------------------------------
David Pollak<feeder.of.the.bears@...> wrote:

2009/7/5 Naftoli Gugenhem <naftoligug@...>

> trait A[T <: A[T]]
> trait B[T < B[T]] extends A[T]
>
> trait C[T <: A[T]]
> A and B are library defined.
> How can I instantiate a C?



trait A[T <: A[T]]

trait B[T <: A[T]] extends A[T]

trait C[T <: A[T]]

class AC extends A[AC]

class BC extends AC with B[AC]

class CC extends C[AC]


--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Re: Type problem

by bearfeeder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

trait A[T <: A[T]]

trait B[T <: A[T]] extends A[T] {
  def name: String
}

trait C[T <: B[_]] {
  def doSomething(p: T) {
    println(p.name)
  }

  def anotherB(b: B[_]) = {
    b.name
  }
}

class AC extends A[AC]

class BC extends AC with B[AC] {
  def name = "Frog"
}

class BC2 extends AC with B[AC] {
  def name = "BC2"
}

class CC extends C[BC] {
}

val cc = new CC
val bc = new BC
val bc2 = new BC2

println(cc.anotherB(bc2))

On Sun, Jul 5, 2009 at 9:12 PM, Naftoli Gugenhem <naftoligug@...> wrote:
Sorry, I didn't ask the question right. I need an instance of C that can handle any instance of any subclass of B.

-------------------------------------
David Pollak<feeder.of.the.bears@...> wrote:

2009/7/5 Naftoli Gugenhem <naftoligug@...>

> trait A[T <: A[T]]
> trait B[T < B[T]] extends A[T]
>
> trait C[T <: A[T]]
> A and B are library defined.
> How can I instantiate a C?



trait A[T <: A[T]]

trait B[T <: A[T]] extends A[T]

trait C[T <: A[T]]

class AC extends A[AC]

class BC extends AC with B[AC]

class CC extends C[AC]


--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Parent Message unknown Re: Type problem

by Naftoli Gugenheim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, I guess I still didn't explain myself. Let me try using more concrete terms.
A is Mapper. B is a supertype of several mapper classes. It's type parameter must be a subclass of B, not A. Also it has a self type of this: T.
C is my MappedOneToMany class. It is _declared_ to take a type parameter derived from _A_. But I need an instance of C that can be used with any B derivative. I can't figure out how to pass B as a type parameter to C so that the instance can contain derivatives of, without getting compiler errors. The problem is that for starters, extends C[B] gives the error that B takes type parameters. But _ doesn't satisfy the compiler, and of course B[_ <: B] doesn't solve the problem
(This leads to a lift question, but even if its answer is no the above question still stands in theory. Must a mapper's type parameter be the concrete subclasses's type, or can you define a nonparameterized base type for a group of mappers?)

-------------------------------------
David Pollak<feeder.of.the.bears@...> wrote:

trait A[T <: A[T]]

trait B[T <: A[T]] extends A[T] {
  def name: String
}

trait C[T <: B[_]] {
  def doSomething(p: T) {
    println(p.name)
  }

  def anotherB(b: B[_]) = {
    b.name
  }
}

class AC extends A[AC]

class BC extends AC with B[AC] {
  def name = "Frog"
}

class BC2 extends AC with B[AC] {
  def name = "BC2"
}

class CC extends C[BC] {
}

val cc = new CC
val bc = new BC
val bc2 = new BC2

println(cc.anotherB(bc2))

On Sun, Jul 5, 2009 at 9:12 PM, Naftoli Gugenhem <naftoligug@...>wrote:

> Sorry, I didn't ask the question right. I need an instance of C that can
> handle any instance of any subclass of B.
>
> -------------------------------------
> David Pollak<feeder.of.the.bears@...> wrote:
>
> 2009/7/5 Naftoli Gugenhem <naftoligug@...>
>
> > trait A[T <: A[T]]
> > trait B[T < B[T]] extends A[T]
> >
> > trait C[T <: A[T]]
> > A and B are library defined.
> > How can I instantiate a C?
>
>
>
> trait A[T <: A[T]]
>
> trait B[T <: A[T]] extends A[T]
>
> trait C[T <: A[T]]
>
> class AC extends A[AC]
>
> class BC extends AC with B[AC]
>
> class CC extends C[AC]
>
>
> --
> Lift, the simply functional web framework http://liftweb.net
> Beginning Scala http://www.apress.com/book/view/1430219890
> Follow me: http://twitter.com/dpp
> Git some: http://github.com/dpp
>



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp