Re: Seq :+ repeat parameter

Simon Schäfer <[email protected]> Thu, 07 Apr 2016 16:10:52 +0200
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>

On 04/07/2016 03:29 PM, Rich Oliver wrote:
> On Thursday, 7 April 2016 13:49:18 UTC+1, Oliver Ruebenacker wrote:
>
>
>          Hello,
>
>       Is it possible that your code does not do what one might think
>     it does?
>
>     scala> val seq = Seq(1, 2, 3)
>     seq: Seq[Int] = List(1, 2, 3)
>
>     scala> val seq2 = seq :+ (4, 5, 6)
>     seq2: Seq[Any] = List(1, 2, 3, (4,5,6))
>
>          Best, Oliver
>
>
> Hi yes you're right. I was forgetting Scala's insanely hyperactive 
> type inference. Well at least I'm not alone, it drove Paul Phillips to 
> despair. Will this madness get worse with type unions?
It is expected to improve the situation, since it would help to infer 
Seq[Int|Tuple3]. On the other hand, that is still not the expected type. 
If you fear type inference, just add more explicit types, that helps a 
lot. I wonder nevertheless how you could end up with such a programming 
mistake, because static analysis can easily warn about that, which is 
what scalac should already do for the above code (at least if you use a 
reasonable actual Scala version).
> -- 
> You received this message because you are subscribed to the Google 
> Groups "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.