I encounter a few problems when I change the function to some of the built-in methods I want to use
I am implementing a small DSL in Scala 2.8 for testing purposes. For example, it should support various checks (if you want, claim). The entire DSL is a bit complicated, but the following simple example shows my problem:
object PimpMyFunction {class A (val b: int) def b (a: A) = ab class ZeroCheck (F : A = & gt; Int) {def isZeroIn (a: A) = f (a) == 0} Built-in def fToCheck (f: A => int): ZeroCheck = new ZeroCheck (f) def main (args : Array [String]] {val a0 = new A (0) val a1 = new A (1) println (fToCheck (b) .isZeroIn (a0)) println (fToCheck (b) .isZeroIn (a1)) println (b First, compile two printline lines (when I call the conversion method explicitly) and work fine, but the last one C (when I want to rely on implicits) produces error:
Error compiled: Object argument in PimpMyFunction object; B for logic; if you treat it as partially applied function If you want to do this, follow this method with '_'.
If I want to change the "normal" examples (which are not functions) in the same way, it also works, So i think that problem Is not related to Coping / import If I follow the instructions of the error message and I println ((b _). Iseroero (a0)) also works, but DSL is targeted at non-technical people, so I would like to keep Syntax as clean and simple as possible. I think I have another alternative solution (B should be an extraordinary feature extension which is already check methods + A => Int) that will support cleaner syntax, but this is more Vocabulary will be less flexible, so I like the inherent method
Any idea how to avoid (b _) syntax and still use implicits?
Scala has to write to ensure that (b _) is to ensure that you In fact, method B wants to be boxed in the function value. If you do not want to write underscore, define the method directly as a function value:
val b = (a: A) => A.b
Comments
Post a Comment