title: How do I write an ML program in Java? With Nested Functions
body: <ol>
  <li>My Exercise gave me this as the original coded.</li>
  <li>They then wanted us to do a java implementation of it.</li>
  <li>I thought that I had now I can't get any of it to make sense.</li>
  <li>There is a spot in this that uses a variable "n" that screws it all up<br>
  somehow.</li>
  <li>This was my real problem unless there is more of it that can be debugged.</li>
  <li><p>I am just trying to learn this stuff before my final next week.</p>
  
  <pre><code>fun f x y =  
      let
        val a = x+1
        fun g 0 = 0
          | g n =
            let
                val a = x+y
                fun h 0 = 0
                  | h k = a+n+g(n-1)
            in
                h (n-1)
            end
      in
          if x = 0
          then g y
          else a + g(f (x-1) y)
      end
  </code></pre></li>
  <li><p>This is the program that I attempted.</p></li>
  <li><p>The original version of the ML code that I am supposed to implement is above.  </p>
  
  <pre><code>public class f {
      static double k;
      static double x;
      static double y;
      static double a, a2;
      static double n;
  
      public static double fn(double x, double y)
      {
          a = x + 1;
          if(x == 0)
              g(y);
          return a + g(fn((x-1), y));
      }
  
      public static double g(double n)
      {
          if(n == 0)
              return 0;
          a2 = (x + y);
          f.n = h(n-1);
          return f.n;
      }
  
      public static double h(double k)
      {
          if(k==0)
              return 0;
          else
          {
              k = a2 + n + g(n-1);
              return k;
          }
      }
  
      public static void main(String[] args)
      {
          /*double arg2[] = null;
          for (int i = 0; i &lt; args.length; i++) {
              arg2[i] = Double.parseDouble(args[i]);
          }*/
          fn(2,1);
      }
  }
  </code></pre></li>
  </ol>