Re: Strange type error

Roman Janusz <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
It fails because 

_ + _ * _

is desugared, as you indented, as 

(x,y,z) => x + y * z

but

(_ + _) * _

is desugared as

z => ((x, y) => x + y) * z

You need to use the full form to express what you want.

W dniu czwartek, 7 maja 2015 11:30:29 UTC+2 użytkownik Toby napisał:
>
> Dear Scala Team,
>
> See below for a simple example that uses placeholder syntax, but fails to 
> compile. Essentially, execute accepts a ternary Double operator. In the 
> first example, where the function literal is _ + _ * _ the compile accepts 
> this, but with additional brackets to change precedence, (_ + _) * _ fails.
>
> I'm sure there is a straightforward explanation for this, but I am 
> currently at a lost as to what it is. Any insights would be much 
> appreciated.
>
> Thanks,
>
> Tobias Grasl
>
> object TestTernaryOp {
>
>  
>
>  def execute(fn : (Double, Double, Double) => Double) = {
>
>    fn(1,2,3)
>
>  }
>
>
>   def main( args : Array[String]) =  {
>
>     // Compiles fine
>     println(execute( _ + _ * _ ))
>
>     // Does not compile - type inference error
>     println(execute( (_ + _) * _ ))
>   }
>
> }
>
>
>

-- 
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.