currying - Can I apply argument defaults when using partial functions in Scala -
I have defined two partial functions (hash), which I expect to get an optional second boolean parameter:
ex> When I call the function with both parameters, it is compiled, but with only one parameter I get a compilation error: I have re-applied it to use partial functions, and I did not have any problem before reconstruction I can force the hash function to use the default. Any ideas why partial function fails to allow implementation of default arguments? Am I doing something wrong with curry using some partial functions? When you use partial applications, you lose the ability to call default method There is a steady thing, so the compiler knows where to look for the default value; A function can be passed in different contexts, so the compiler will not normally need that information which it should be able to implement the default parameter. To think about it in any other way, the function only knows how many logic there is only one method, def SHA1 = hasd (MessageDigest.getInstance ("SHA-1") _DrD MD5 = hash (MessageDigest.getInstance ("MD5") _ Personal DHHash (Algorithm: hash algorithm) ( S: string, urlencode: boolean = false) = {val form = if (urlencode) "% 2005 2005 02x" other "% 02X" (algorithm.s.b.tes map) (form format _)). MkString}
// First 3 test OK Val test1 = hash ("Foo", true) Val test2 = hash (Message Dictate.Get instance ("SHA-1")) ("FU") Val test3 = SHA1 (" Fu ", true) // Not enough arguments apply to the method: String Function2 in the attribute (v1: string, v2: boolean) Unspecified value parameter v2 val test4 = SHA1 ("foo")
apply , that you pass parameters Are; Otherwise, you need different methods in different ways, for example, function 2-that-take-two-criteria and function 2-the same-as-one-parameter-along -the -A-stored-default
Comments
Post a Comment