package prelude;

/** arithmetic operations; analogous to the Haskell `Num` type class
 */
public final class Num {
  /** curried addition of integers */
  public static
  Thunk<Fn<Integer, Fn<Integer, Integer>>>
  addI() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() + y.eval()
  ))); }

  /** curried subtraction of integers */
  public static
  Thunk<Fn<Integer, Fn<Integer, Integer>>>
  subtractI() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() - y.eval()
  ))); }

  /** curried multiplication of integers */
  public static
  Thunk<Fn<Integer, Fn<Integer, Integer>>>
  mulI() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() * y.eval()
  ))); }

  ///

  /** curried addition of doubles */
  public static
  Thunk<Fn<Double, Fn<Double, Double>>>
  addD() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() + y.eval()
  ))); }

  /** curried subtraction of doubles */
  public static
  Thunk<Fn<Double, Fn<Double, Double>>>
  subtractD() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() - y.eval()
  ))); }

  /** curried multiplication of doubles */
  public static
  Thunk<Fn<Double, Fn<Double, Double>>>
  mulD() { return Thunk.ready(x -> Thunk.ready(y -> Thunk.lazy(__ ->
    x.eval() * y.eval()
  ))); }
}

@@ -11,16 +11,48 @@
 elude;%0A%0A
+import static prelude.Thunk.*;%0A%0A
 /** arit
@@ -1362,11 +1362,268 @@
   ))); %7D
+%0A%0A  public static%0A  Thunk%3CFn%3CDouble, Fn%3CDouble, Double%3E%3E%3E%0A  divD() %7B return fn(x -%3E fn(y -%3E thunk(__ -%3E%0A    x.eval() / y.eval()%0A  ))); %7D%0A%0A  public static%0A  Thunk%3CFn%3CInteger, Double%3E%3E%0A  fromInteger() %7B return fn(x -%3E thunk(__ -%3E%0A    (double) x.eval()%0A  )); %7D
 %0A%7D%0A

add Num.{divD :: Double -> Double -> Double and fromInteger :: Integer -> Double}