Scala compilers complains about "ambiguous reference to overloaded definition" when asking for a function in the second parameters set -


this seems strange. following compile fine:

def foo(s: string) = "balsh" def foo(s: string)(s2: string) = "kahsd" 

if make second parameter implicit, still compiles fine , all.

however, following not:

def foo(s: string) = "bjda" def foo(s: string)(fun: string => string) = fun(s) 

^that 1 not compile due "ambiguous reference overloaded definition".

my original thought way scala converting functions java causing signatures of 2 same. however, looking @ compile coded (for second function since not compile both) javap, see such function converted into:

public java.lang.string foo(java.lang.string, scala.function1); 

so separate method created, different signature. why failing compile?

now make matters more confusing, following compiles fine!

def foo(s: string) = "bjda" def foo(s: string, fun: string => string) = fun(s) 

if make function part of first set of parameters, fine!

does know why happening?

edit:

so tried this:

object main {   def write(s: string) = "sasd"   def write(s: string)(implicit s2: string => string) = s2(s) } 

i made function in second parameter implicit. lo , behold, compiles.

this java code produces:

public final class main$ extends java.lang.object{     public static final main$ module$;     public static {};     public java.lang.string write(java.lang.string);     public java.lang.string write(java.lang.string, scala.function1); } 

this have expected original 1 without implicit!

i'd guess there no way compiler select between 2 differing in return types. not possible dispatch based on return type of function parameters. think of signatures this:

def foo(s: string): string def foo(s: string): string => string 

not sure why work if make implicit, same error (as expect).

def foo(s: string, fun: string => string)  

on other hand has different parameter list possible dispatch to.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -