function - How to specialize a type parameterized argument to multiple different types for in Scala? -


I need a back-check (please)

I have written in an article () I believe in Scala that you can not specify a function that takes an argument that is a function with an unbound type parameter. I have edited this article to simplify and simplify the example.

The following code introduces a feature GenericFn which imitates the Scala Function1 attribute, in addition the function has a free-type parameter:

  Object typeexample { Specialty numberBage {DF result: string} class A extended number of fractions {DF result = "A"} class B expanded number of base {DF result = "B"} attribute GenericFn {def} [X & lt; : Number Buzz] (X: X): String} DF Specialist and Aptitude (F: Generic FN): String = {F [A] (New A ()) + F [B] (New B)) DIF Main (Args: array [string]): unit = {val f = new genericFn {def} [x and lieutenant: numberbase] (x: x): string = {x.result}} println (specialized endepeptius (f))} }  

This works, but is there a way to do this without the GenericFn attribute (use standard function notation)? For example, the code below is unsuccessful with compile-time errors: "Type mismatch; found: TypeExample2.A Required: _ $ 1 where Type _ $ 1 <: typeExample2.NumberBase":

  DIF Specialist and Aptitude String = {F (New A ()) + F (New B ())}  

value 'g' because we want to pass it. Div class = "text-post" itemprop = "text">

Around. Scal value (of course) can not be polymorphic types, even if they have function value. So how to give a type, where no part of it is unknown?

So I believe that a solution is to use wildcard (a form of non-existent abstract):

  def g (F: array [_ and lieutenant: Number Buzz [_]] => double, jade: array [double]): double  

There is a prose statement for the type of type: from a function array [t] and array [double ] Two times, where T is the some type that extends to double "something" is a word that points to non-existent abstraction, we ask that such a process Yes, we are not paid attention to this point, which is that which is.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -