is it a bug in the compiler?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

is it a bug in the compiler?

Sadek Drobi
https://gist.github.com/529983

scala> List("one","two") foldLeft ("") (_+_)
<console>:6: error: missing parameter type for expanded function ((x$1, x$2) => x$1.$plus(x$2))
       List("one","two") foldLeft ("") (_+_)
                                        ^
// Int ???

scala> List("one","two") foldLeft ("") ((_+_):(String,String) => String)
<console>:6: error: type mismatch;
 found : (String, String) => String
 required: Int
       List("one","two") foldLeft ("") ((_+_):(String,String) => String)
                                             ^


scala> List("one","two").foldLeft ("") (_+_)
res2: java.lang.String = onetwo

--
www.sadekdrobi.com
ʎdoɹʇuǝ
Reply | Threaded
Open this post in threaded view
|

Re: is it a bug in the compiler?

Paul Phillips-3
On Fri, Nov 19, 2010 at 09:52:25PM +0100, Sadek Drobi wrote:
> scala> List("one","two") foldLeft ("") (_+_)
> <console>:6: error: missing parameter type for expanded function
> ((x$1, x$2) => x$1.$plus(x$2))
>        List("one","two") foldLeft ("") (_+_)
>                                         ^
> // Int ???

That's correct, Int.

 ""(5) // valid expression
 ""(_ + _) // less valid expression

Without the dot, your first argument to foldLeft is ""(_ + _) because
the parens bind tightly.  You need the dot to bind even more tightly.

--
Paul Phillips      | Eschew mastication.
Caged Spirit       |
Empiricist         |
ha! spill, pupil   |----------* http://www.improving.org/paulp/ *----------
Reply | Threaded
Open this post in threaded view
|

Re: is it a bug in the compiler?

Sadek Drobi
oh that makes perfect sense. Didn't pay attention to apply on Strings

On Fri, Nov 19, 2010 at 10:14 PM, Paul Phillips <[hidden email]> wrote:
On Fri, Nov 19, 2010 at 09:52:25PM +0100, Sadek Drobi wrote:
> scala> List("one","two") foldLeft ("") (_+_)
> <console>:6: error: missing parameter type for expanded function
> ((x$1, x$2) => x$1.$plus(x$2))
>        List("one","two") foldLeft ("") (_+_)
>                                         ^
> // Int ???

That's correct, Int.

 ""(5)          // valid expression
 ""(_ + _)      // less valid expression

Without the dot, your first argument to foldLeft is ""(_ + _) because
the parens bind tightly.  You need the dot to bind even more tightly.

--
Paul Phillips      | Eschew mastication.
Caged Spirit       |
Empiricist         |
ha! spill, pupil   |----------* http://www.improving.org/paulp/ *----------



--
www.sadekdrobi.com
ʎdoɹʇuǝ