- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Type-issue
Sat, 2010-04-24, 13:07
I'm not sure if this is related to #2346 or #2308 however I just ran into the following issue (minimized as much as I could think to do):
def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
val fiver : A => Int = ignore => 5
col.foreach(fiver)
}
traversable-types.scala:10: error: type mismatch;
found : (A) => Int
required: (Any) => ?
col.foreach(fiver)
Is this bug related, or should I post a new one?
Thanks!
- Josh
def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
val fiver : A => Int = ignore => 5
col.foreach(fiver)
}
traversable-types.scala:10: error: type mismatch;
found : (A) => Int
required: (Any) => ?
col.foreach(fiver)
Is this bug related, or should I post a new one?
Thanks!
- Josh
Sat, 2010-04-24, 13:57
#2
Re: Type-issue
This works:
scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
| val fiver : A => Int = ignore => 5
| col.foreach(fiver)
| }
test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
I'd like to hear a precise explanation of the difference.
-jason
On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth wrote:
> I'm not sure if this is related to #2346 or #2308 however I just ran into
> the following issue (minimized as much as I could think to do):
>
> def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> val fiver : A => Int = ignore => 5
> col.foreach(fiver)
> }
>
> traversable-types.scala:10: error: type mismatch;
> found : (A) => Int
> required: (Any) => ?
> col.foreach(fiver)
>
>
> Is this bug related, or should I post a new one?
>
>
> Thanks!
>
> - Josh
>
>
>
Sat, 2010-04-24, 14:07
#3
Re: Type-issue
On Sat, Apr 24, 2010 at 2:50 PM, Jason Zaugg <jzaugg@gmail.com> wrote:
This works:
scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
| val fiver : A => Int = ignore => 5
| col.foreach(fiver)
| }
test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
I'd like to hear a precise explanation of the difference.
+1. Ran into this yesterday.
-jason
On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth <joshua.suereth@gmail.com> wrote:
> I'm not sure if this is related to #2346 or #2308 however I just ran into
> the following issue (minimized as much as I could think to do):
>
> def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> val fiver : A => Int = ignore => 5
> col.foreach(fiver)
> }
>
> traversable-types.scala:10: error: type mismatch;
> found : (A) => Int
> required: (Any) => ?
> col.foreach(fiver)
>
>
> Is this bug related, or should I post a new one?
>
>
> Thanks!
>
> - Josh
>
>
>
--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall
Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang
Sat, 2010-04-24, 14:07
#4
Re: Type-issue
On Sat, Apr 24, 2010 at 2:50 PM, Jason Zaugg <jzaugg@gmail.com> wrote:
This works:
scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
| val fiver : A => Int = ignore => 5
| col.foreach(fiver)
| }
test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
I'd like to hear a precise explanation of the difference.
+1. Ran into this yesterday.
-jason
On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth <joshua.suereth@gmail.com> wrote:
> I'm not sure if this is related to #2346 or #2308 however I just ran into
> the following issue (minimized as much as I could think to do):
>
> def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> val fiver : A => Int = ignore => 5
> col.foreach(fiver)
> }
>
> traversable-types.scala:10: error: type mismatch;
> found : (A) => Int
> required: (Any) => ?
> col.foreach(fiver)
>
>
> Is this bug related, or should I post a new one?
>
>
> Thanks!
>
> - Josh
>
>
>
--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall
Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang
Sat, 2010-04-24, 14:17
#5
Re: Re: Type-issue
I think this has been discussed before, but I couldn't find the link.
CC[_] <: Traversable[_]
means
CC[X] <: Traversable[Y] forSome { type Y }
so that the upper bound is unrelated to the type parameter to CC.
CC[X] <: Traversable[X]
constrains the type parameter of Traversable to be the same as that for CC.
Not sure if this is of further help, but:
A.scala
object A
{
def test2[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = ()
def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = ()
}
$ scalac -Xprint:typer -Xprint-types A.scala
...
def test2[A >: Nothing <: Any, CC[_ >: Nothing <: Any] >: [_]Nothing <: [_]Traversable[_]](col: CC[A]): Unit = (){Unit};
def test3[A >: Nothing <: Any, CC[X >: Nothing <: Any] >: [X]Nothing <: [X]Traversable[X]](col: CC[A]): Unit = (){Unit}
...
and possibly
$ scalac -Ybrowse:typer A.scala
to explicitly see that Traversable[_] is an existential type.
-Mark
On Saturday 24 April 2010, Jason Zaugg wrote:
> This works:
>
> scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
> | val fiver : A => Int = ignore => 5
> | col.foreach(fiver)
> | }
> test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
>
> I'd like to hear a precise explanation of the difference.
>
> -jason
>
> On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth wrote:
> > I'm not sure if this is related to #2346 or #2308 however I just ran into
> > the following issue (minimized as much as I could think to do):
> >
> > def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> > val fiver : A => Int = ignore => 5
> > col.foreach(fiver)
> > }
> >
> > traversable-types.scala:10: error: type mismatch;
> > found : (A) => Int
> > required: (Any) => ?
> > col.foreach(fiver)
> >
> >
> > Is this bug related, or should I post a new one?
> >
> >
> > Thanks!
> >
> > - Josh
> >
> >
> >
>
>
Sat, 2010-04-24, 14:17
#6
Re: Re: Type-issue
I think this has been discussed before, but I couldn't find the link.
CC[_] <: Traversable[_]
means
CC[X] <: Traversable[Y] forSome { type Y }
so that the upper bound is unrelated to the type parameter to CC.
CC[X] <: Traversable[X]
constrains the type parameter of Traversable to be the same as that for CC.
Not sure if this is of further help, but:
A.scala
object A
{
def test2[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = ()
def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = ()
}
$ scalac -Xprint:typer -Xprint-types A.scala
...
def test2[A >: Nothing <: Any, CC[_ >: Nothing <: Any] >: [_]Nothing <: [_]Traversable[_]](col: CC[A]): Unit = (){Unit};
def test3[A >: Nothing <: Any, CC[X >: Nothing <: Any] >: [X]Nothing <: [X]Traversable[X]](col: CC[A]): Unit = (){Unit}
...
and possibly
$ scalac -Ybrowse:typer A.scala
to explicitly see that Traversable[_] is an existential type.
-Mark
On Saturday 24 April 2010, Jason Zaugg wrote:
> This works:
>
> scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
> | val fiver : A => Int = ignore => 5
> | col.foreach(fiver)
> | }
> test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
>
> I'd like to hear a precise explanation of the difference.
>
> -jason
>
> On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth wrote:
> > I'm not sure if this is related to #2346 or #2308 however I just ran into
> > the following issue (minimized as much as I could think to do):
> >
> > def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> > val fiver : A => Int = ignore => 5
> > col.foreach(fiver)
> > }
> >
> > traversable-types.scala:10: error: type mismatch;
> > found : (A) => Int
> > required: (Any) => ?
> > col.foreach(fiver)
> >
> >
> > Is this bug related, or should I post a new one?
> >
> >
> > Thanks!
> >
> > - Josh
> >
> >
> >
>
>
This works:
scala> def test3[A, CC[X] <: Traversable[X]](col : CC[A]) : Unit = {
| val fiver : A => Int = ignore => 5
| col.foreach(fiver)
| }
test3: [A,CC[X] <: Traversable[X]](col: CC[A])Unit
I'd like to hear a precise explanation of the difference.
-jason
On Sat, Apr 24, 2010 at 2:07 PM, Josh Suereth wrote:
> I'm not sure if this is related to #2346 or #2308 however I just ran into
> the following issue (minimized as much as I could think to do):
>
> def test3[A, CC[_] <: Traversable[_]](col : CC[A]) : Unit = {
> val fiver : A => Int = ignore => 5
> col.foreach(fiver)
> }
>
> traversable-types.scala:10: error: type mismatch;
> found : (A) => Int
> required: (Any) => ?
> col.foreach(fiver)
>
>
> Is this bug related, or should I post a new one?
>
>
> Thanks!
>
> - Josh
>
>
>