functional programming - What is the point of multiple parameter clauses in function definitions in Scala? -
I am trying to understand the point of this language feature of several parameter segments and why you would use it for example What is the difference between these two functions?
class WTF {def} doublemclause (x: int) (y: int) = x + y def acronym (x: int, y: int) = x + y}> & gt; Val underTest = new WTF & gt; & Gt; Undeste DoubleClickClues (1) (1) // result '2' & gt; & Gt; UnderTest.OneParamClause (1,1) // is the result '2' There is something on it to see that it matters to you.
NB: Tip These are called 'parameter clauses', but I think some people also call them 'parameter lists'. There are three practical uses of many parameter lists here,
-
It is especially useful when using top sequence methods to assist with the type estimate, the first parameter x with parameter a of g2 is approximate, so in the second parameter, the function argument f f = f (x) g1 (2, x => gt); df g1 [a] (x: a, F: A => A) = F (x) // Ruti: parameters for the argument of the missing x def g2 [A] (x: A) (f: A = & gt; A) = f (x) g2 (2) {x = & gt; X} // is approximate; Also, a good syntax -
Only the last parameter list can be marked for the underlying parameters, and a single parameter list can be embedded and non-indirect parameter Can not mix For definition of g3 below, two parameter lists are required, // correspond to a reference: G3 [A: Ordering] (X: A) DRF G3 [A] (X: A) (built-in eve: command [A]) {} -
to set the default value based on the previous parameters ,
Comments
Post a Comment