This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Type-issue

6 replies
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
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


Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
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
>
>
>

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
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
>
>
>

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
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
Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
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
Mark Harrah
Joined: 2008-12-18,
User offline. Last seen 35 weeks 3 days ago.
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
> >
> >
> >
>
>

Mark Harrah
Joined: 2008-12-18,
User offline. Last seen 35 weeks 3 days ago.
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
> >
> >
> >
>
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland