You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Of course in my actual program "doit" actually does something and only evaluates f occasionally.
The f parameter is implicit because I want callers to be able to use an implicit default value when they know that f will never actually be evaluated:
implicitvaldefault=0
Unfortunately there seems to be no way to create a val, var, or def in such a way that Scala will choose it as the implicit argument to doit. I tried the following:
If the compiler allows the creation of an implicit by-name parameter, then it should be willing to select an implicit argument for it. If not, then it should be illegal to create the implicit by-name parameter in the first place.
The text was updated successfully, but these errors were encountered:
Welcome to Scala version 2.8.0.r0-b20091123212008 (JavaHotSpot(TM) 64-BitServerVM, Java1.6.0_15).
Type in expressions to have them evaluated.
Type:help for more information.
scala>defdoit(implicitf: =>Int) = f *2
doit: (implicitf: =>Int)Int
scala>implicitvalx=42
x:Int=42
scala> doit
<console>:7:error: could not find implicit value for parameter f: =>Int
doit
^
scala>implicitvalx: () =>Int= () =>42
x: () =>Int= <function0>
scala> doit
<console>:9:error: could not find implicit value for parameter f: =>Int
doit
^
I created a function like this:
Of course in my actual program "doit" actually does something and only evaluates f occasionally.
The f parameter is implicit because I want callers to be able to use an implicit default value when they know that f will never actually be evaluated:
Unfortunately there seems to be no way to create a val, var, or def in such a way that Scala will choose it as the implicit argument to doit. I tried the following:
Of course the third one doesn't even compile.
If the compiler allows the creation of an implicit by-name parameter, then it should be willing to select an implicit argument for it. If not, then it should be illegal to create the implicit by-name parameter in the first place.
The text was updated successfully, but these errors were encountered: