Stefan,

The Mapper[T <: Mapper[T]] type allows for:

User extends Mapper[User]

It means that T is the the class and it is the current subclass of Mapper.

Combined with the {
self: T =>
}

Construct, we know that T is the actual class that the current Mapper is the
subclass of.

And yes, the compiler has a special flag to be able to resolve the type of T
to User during the evaluation of User extends Mapper[User]

Make sense?

Thanks,

David

On Fri, Mar 27, 2009 at 1:52 PM, Stefan Scott <[email protected]>wrote:

>
> Hi -
>
> Sorry to be asking a Scala syntax question here in the Lift group, but
> I figured somebody here would know, since this Scala syntax occurs
> quite a bit in the Lift source code.
>
> When reading some of the Lift source I come across a particular Scala
> "idiom" involving parameterized types with bounds, whose semantics I'm
> unsure of.
>
> For example:
>
> class MappedTextarea[ T <: Mapper[ T ] ] ( owner : T, maxLen: Int )
> extends
>      MappedString[ T ]( owner, maxLen ) { ... }
>
> What I'm unsure about here is the part where it says:
>
> T <: Mapper[ T ]
>
> At first, this made no sense to me - how could a type T be a subtype
> of type Mapper[ T ] ?
>
> Then I guessed that maybe the two occurrences of T are unrelated to
> each other - ie, class MappedTextarea is parameterized over a type T,
> which must be a subtype of a type Mapper[ T ] -- where the second T is
> actually in a separate scope so that it has nothing to do with the
> first T.
>
> Is that what this really means?
>
> And, if that's really the case, then I guess the other occurrences of
> T later in the text:
>
> owner : T
> MappedString[ T ]
>
> are also referring to the first occurrence of T -- the type T which is
> upper-bounded by type Mapper[ T ].
>
> Finally, does this mean that the above code could also have been
> written equivalently as follows:
>
> class MappedTextarea[ T <: Mapper[ U ] ] ( owner : T, maxLen: Int )
> extends
>      MappedString[ T ]( owner, maxLen ) { ... }
>
> using U instead of T for the type parameter that's in a separate
> scope?
>
> Thanks for any help.
>
> - Stefan Scott
>
>
>
>
>
> >
>


-- 
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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to