2

In the code below, the first function compiles. The second doesn't compile.

type FTDoubleDouble_Double = (Double, Double) => Double val _dividedBy: FTDoubleDouble_Double = { _ / _.toDouble } val _dividedByThenLog: FTDoubleDouble_Double = { val result1 = _ / _.toDouble scala.math.log(result1) } 

The compilation error is

cannot resolve symbol /

I am sure this is basic, but I am a bit confused.

1

1 Answer 1

3

In the 1st case the type ascription helps the compiler figure out what the underscores are supposed to represent: 2 Double values. (Which makes the .toDouble cast redundant and pointless.)

The 2nd case doesn't compile because there aren't enough hints to help the compiler.

You can fix that...

val result1 :FTDoubleDouble_Double = _ / _ 

...but then you've got another problem.

scala.math.log(result1) //error 

math.log() takes a Double as the passed-in parameter, which you don't have.

Perhaps this is what you want:

val _dividedByThenLog: FTDoubleDouble_Double = (d1 :Double, d2 :Double) => scala.math.log(d1 / d2) 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks...and yes, the toDouble is redundant. I guess I must have had an Int argument originally and forgot to delete when I changed to Double

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.