In scala,
Can you explain what is the difference between them, and why the first one use "() => Int", and second one use "Int => () => Int"
1.
val constant5 : () => Int = {
()=>5
}
2.
val constant : Int => () => Int = {
(n :Int)=>(()=> n )
}
There's a minute difference between the two statements in Scala.
1. Statement 1 will always return constant i.e 5 which is an integer value. No matter where this function is being called it will always return integer value 5. It does not accepts any parameter so we can call this function from anywhere like below:
val a : Int = constant5()
So, a will have value of 5 returned from statement 1.
Similarly you can return any value by making same constant structure and just changing the digit part of the constant. For ex- if you want a constant that return a number 'X' write:
val a : Int = constantX()
2. Statement 2 is generalized function which accepts an Integer parameter and returns the same integer value that is being given as parameter. You can pass any Integer value to this function call and it will return that same integer value. It is also called an Identity function. You can use this as below:
val a: () => Int = constant (2)
This above statement will return a function, to fetch the value use below statement.
val b: Int = a ()
So, here we called function 'a' returned from above statement and it will give us our value 2 which was given as parameter.
The reason why the first one uses "() => Int" and second one uses "Int => () => Int" is that first one accepts no parameter and returns the constant as specified in its declaration whereas second one accepts or requires an Integer parameter to be passed and it returns the same Integer parameter when the function is being called anywhere in the program.
In scala, Can you explain what is the difference between them, and why the first one...
Consider the following Scala code that uses classes, objects, inheritance and dynamic method binding abstract class A { def m) Int 1 val a Int = 2 class B extends A { val b: String "one" override def m() : Int = 3 def n(): Int 4 class C extends A { val x : Int 5 override def m() : Int = 6 val array an array of ten A objects array (5) val obj: A obj.m() = (a)...
SCALA HELP Use Scala to do your calculations: ( see notes on doing this for the first two segmentations) a. Calculate the overall entropy of this set b. Calculate the IG information gain by splitting on head shape c. Calculate the IG information gain by splitting on body shape d. Calculate the IG information gain by splitting on color. d. Of these three, which is the best attribute to do segmentation with, why ? object quiz { println("Welcome to the...
1. In Module 2 "headers" and "footers" are described. Explain the difference between them and how to set them up. How can they improve your workbook's appearance? 2. A cell containing a number displays #######. Why does this occur and what can you do to fix it?
Using the five-component model, explain the difference between IT and IS. Explain why you can buy IT, but you can never buy IS. What does that mean to you, as a potential future business manager?
why
o=n=o is not one of them
and can you explain this answer for me?
8.70 Resonance must be present any time that a single Lewis structure is inadequate in explaining one or more aspects of a molecule or ion. The two N-O bonds in NO2 are equivalent in bond length and bond energy; no single Lewis structure can account for this. The following Lewis structures may be drawn for NO2: 6=–vò=N- v o -N=0 : < = The average...
1-2 paragraphs Briefly explain the difference between Classical Architecting and the Form-First Paradigm (Builder-Architected). Why would you choose one approach over the other?
Suppose there are two identical gold bars that you own. The only difference between them is how you acquired them. One bar was won as a prize, the other you purchased. What is the difference in the cost of retaining ownership in the two bars? Explain. (hint: recall the distinction between accounting and opportunity costs). Will there be any predicted difference in the use of the bars? Explain.
First Aid Test #1 name 1. What is the difference between an open and closed fracture? 2. How do you clean a wound, and what should you not use to clean a wound. 3. List and explain 5 types of open wounds. 4. How do you know that a wound is infected? 5. How do you care for burns? 6. When is a Hemostatic dressing used and why?
1. What is the difference between shareholder and stakeholder? Can you briefly explain.
Can you explain what the difference is between direct learning activities and indirect learning activities?Can you explain what the difference is between direct learning activities and indirect learning activities?