arity

Can I pass an arbitrary function to another function in Scala?

亡梦爱人 提交于 2019-11-29 19:35:35
问题 I'm new to Scala, and being able to pass functions to other functions is pretty neat-- but can I pass an arbitrary function reference to another function? The arity of said functional parameter will be fixed (that said, I'm also curious about whether you can pass a function with arbitrary arity as well). I keep getting tripped up on type errors. I've tried using Any but it doesn't seem to help. E.g., I have the code below: class CodeRunner(val user_defined: (Int) => Unit) { def run(input: Int

Why is this Java method call considered ambiguous?

懵懂的女人 提交于 2019-11-29 17:02:54
问题 I've come across a strange error message that I believe may be incorrect. Consider the following code: public class Overloaded { public interface Supplier { int get(); } public interface Processor { String process(String s); } public static void load(Supplier s) {} public static void load(Processor p) {} public static int genuinelyAmbiguous() { return 4; } public static String genuinelyAmbiguous(String s) { return "string"; } public static int notAmbiguous() { return 4; } public static String

Arity-generic programming in Agda

走远了吗. 提交于 2019-11-29 14:42:10
问题 How to write arity-generic functions in Agda? Is it possible to write fully dependent and universe polymorphic arity-generic functions? 回答1: I'll take an n-ary composition function as an example. The simplest version open import Data.Vec.N-ary comp : ∀ n {α β γ} {X : Set α} {Y : Set β} {Z : Set γ} -> (Y -> Z) -> N-ary n X Y -> N-ary n X Z comp 0 g y = {!!} comp (suc n) g f = {!!} Here is how N-ary is defined in the Data.Vec.N-ary module: N-ary : ∀ {ℓ₁ ℓ₂} (n : ℕ) → Set ℓ₁ → Set ℓ₂ → Set (N

Find function's arity in Common Lisp

我与影子孤独终老i 提交于 2019-11-29 13:36:46
I've been doing some Genetic Programming and I've been separating functions into different function sets based on their arity; it's all rather complex. I'd like to know if there's a simpler way to to do it. For example, if there's a function that returns the arity of a given function. Cheers in advance. For interpreted functions you should be able to use function-lambda-expression . For compiled functions, alas, this function often returns nil , so you will have to use an implementation-dependent function ( clocc / port / sys.lisp ): (defun arglist (fn) "Return the signature of the function."

Get function arity from template parameter

佐手、 提交于 2019-11-28 10:04:14
How can I get the arity of an arbitrary function type used as a template parameter? The function can be a normal function, a lambda or a functor. Example: template<typename TFunc> std::size_t getArity() { // ...? } template<typename TFunc> void printArity(TFunc mFunc) { std::cout << "arity: " << getArity<TFunc>() << std::endl; } void testFunc(int) { } int main() { printArity([](){}); // prints 0 printArity([&](int x, float y){}); // prints 2 printArity(testFunc); // prints 1 } I have access to all C++14 features. Do I have to create specialization for every function type (and all respective

Get function arity from template parameter

白昼怎懂夜的黑 提交于 2019-11-27 03:21:27
问题 How can I get the arity of an arbitrary function type used as a template parameter? The function can be a normal function, a lambda or a functor. Example: template<typename TFunc> std::size_t getArity() { // ...? } template<typename TFunc> void printArity(TFunc mFunc) { std::cout << "arity: " << getArity<TFunc>() << std::endl; } void testFunc(int) { } int main() { printArity([](){}); // prints 0 printArity([&](int x, float y){}); // prints 2 printArity(testFunc); // prints 1 } I have access

Get a function's arity

萝らか妹 提交于 2019-11-26 20:22:33
In Javascript, how can one determine the number of formal parameters defined for a function? Note, this is not the arguments parameter when the function is called, but the number of named arguments the function was defined with. function zero() { // Should return 0 } function one(x) { // Should return 1 } function two(x, y) { // Should return 2 } Josh Lee > zero.length 0 > one.length 1 > two.length 2 Source A function can determine its own arity (length) like this: // For IE, and ES5 strict mode (named function) function foo(x, y, z) { return foo.length; // Will return 3 } // Otherwise

Get a function&#39;s arity

旧街凉风 提交于 2019-11-26 07:36:28
问题 In Javascript, how can one determine the number of formal parameters defined for a function? Note, this is not the arguments parameter when the function is called, but the number of named arguments the function was defined with. function zero() { // Should return 0 } function one(x) { // Should return 1 } function two(x, y) { // Should return 2 } 回答1: > zero.length 0 > one.length 1 > two.length 2 Source A function can determine its own arity (length) like this: // For IE, and ES5 strict mode