/* This program illustrates the use of "delegates", which allows for higher-order functions (that we saw in Scheme and Perl) in the context of the oop type system. */ using System; public delegate int intfun (int x); // a delegate declaration // A delegate is used like a class in that it can be instantiated with // and function with type int->int. Java has a similar mechanism where // one can inline a class definition. public class delegates { public static int sqr(int x) { return x*x; } // used to instantiate intfun public static int dec(int x) { return x-1; } // used to instantiate intfun // apply a delgate function to every element of an array: public static void map(intfun f, int[] A) { for (int i=0;i