Пример #1
0
 static bool Elem <EqA, A>(A x, A[] ys) where EqA : struct, Eq <A>
 {
     for (int i = 0; i < ys.Length; i++)
     {
         if (Overloads.Eq <EqA, A>(x, ys[i]))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #2
0
        /*
         * Now every dictionary that implements Ord<A> must implement Eq<A> too, and can be used
         * as such when required.
         *
         * Of course, in CS we have to make Dictionary construction and passing (as types, not values) explicit.
         * This is what a modified C# compiler would hopefully be able to do for you,
         * just like Haskell does by solving constraints to construct dictionaries at compile time.
         *
         * The point is that the underlying mechanism for implementing Haskell Type Classes is already there!
         *
         */

        public static void Run()
        {
            Console.WriteLine("Find Test {0}", Elem <EqInt, int>(1, new int[] { 1, 2, 3 }));
            Console.WriteLine("Find Test {0}", Elem <EqInt, int>(4, new int[] { 1, 2, 3 }));

            Console.WriteLine("Equals Test {0}",
                              Overloads.Eq <EqArray <int[], EqArray <int, EqInt> >, int[][]>(new int[][] { new int[] { 1, 2 }, new int[] { 3, 4 } },
                                                                                             new int[][] { new int[] { 1, 2 }, new int[] { 3, 4 } }));

            Console.WriteLine("Equals Test {0}",
                              Overloads.Eq <EqArray <int[], EqArray <int, EqInt> >, int[][]>(new int[][] { new int[] { 1, 2 }, new int[] { 3, 4 } },
                                                                                             new int[][] { new int[] { 1, 2 }, new int[] { 3, 5 } }));
        }
Пример #3
0
 public bool Equals(A[] a, A[] b)
 {
     if (a == null)
     {
         return(b == null);
     }
     if (b == null)
     {
         return(false);
     }
     if (a.Length != b.Length)
     {
         return(false);
     }
     for (int i = 0; i < a.Length; i++)
     {
         if (!Overloads.Eq <EqA, A>(a[i], b[i]))
         {
             return(false);
         }
     }
     return(true);
 }