- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
lower and upper bound
Wed, 2009-01-07, 06:36
I'd like to see an example of specifying both a lower and an upper bound
in a type parameter. I tried for example this:
def m[Int >: T <: AnyRef](x: T) = println(x)
but I get:
:4: error: not found: type T
If I omit the lower bound, it works. I got the syntax from Programming
in Scala, perhaps it's a typo there? In 7.3 it reads: "One can also
combine lower and upper bounds, as in T >: S <: U."
Thanks,
Dimitris Andreou
Wed, 2009-01-07, 10:27
#2
Re: lower and upper bound
Right, it has to go at the beginning. I was wondering, though, whether we could introduce in Scala this special syntax:
S <: T <: U
since it is mathematically/aesthetically more appealing.
Christos.
On Wed, Jan 7, 2009 at 7:49 AM, Tony Sloane <inkytonik@gmail.com> wrote:
--
__~O
-\ <, Christos KK Loverdos
(*)/ (*) http://ckkloverdos.com
S <: T <: U
since it is mathematically/aesthetically more appealing.
Christos.
On Wed, Jan 7, 2009 at 7:49 AM, Tony Sloane <inkytonik@gmail.com> wrote:
On 07/01/2009, at 4:35 PM, Andreou Dimitris wrote:
I'd like to see an example of specifying both a lower and an upper bound in a type parameter. I tried for example this:
def m[Int >: T <: AnyRef](x: T) = println(x)
but I get:
<console>:4: error: not found: type T
Try
def m[T >: Int <: AnyRef](x: T) = println(x)
If I omit the lower bound, it works. I got the syntax from Programming in Scala, perhaps it's a typo there? In 7.3 it reads: "One can also combine lower and upper bounds, as in T >: S <: U."
In this excerpt, T is the type whose bounds you are defining, S is the lower bound and U is the upper bound. T must come first, not in the middle.
regards,
Tony
--
__~O
-\ <, Christos KK Loverdos
(*)/ (*) http://ckkloverdos.com
On 07/01/2009, at 4:35 PM, Andreou Dimitris wrote:
> I'd like to see an example of specifying both a lower and an upper
> bound in a type parameter. I tried for example this:
>
> def m[Int >: T <: AnyRef](x: T) = println(x)
>
> but I get:
>
> :4: error: not found: type T
Try
def m[T >: Int <: AnyRef](x: T) = println(x)
>
>
> If I omit the lower bound, it works. I got the syntax from
> Programming in Scala, perhaps it's a typo there? In 7.3 it reads:
> "One can also combine lower and upper bounds, as in T >: S <: U."
In this excerpt, T is the type whose bounds you are defining, S is the
lower bound and U is the upper bound. T must come first, not in the
middle.
regards,
Tony