module type ArithmeticInterface = sig
  type t;;
  
  val zero : t;;

  exception ArithmeticFailure;;

  val succ : t -> t;;
  val pred : t -> t;;
  val sum : t -> t -> t;;
  val times : t -> t -> t;;
  val minus : t -> t -> t;;
  val divide : t -> t -> t;;
  
  val to_string : t -> string;;
  val of_string : string -> t;;
end;;

module Arithmetic : ArithmeticInterface = struct
  type natplus =
    | One
    | Succ of natplus;;
  type myint =
    | Zero
    | Positive of natplus
    | Negative of natplus;;

  type t = myint;;
  
  let rec int_of_natplus n =
    match n with
      | One -> 1
      | Succ n_minus_1 -> 1 + (int_of_natplus n_minus_1);;
  let to_int x =
    match x with
      | Zero -> 0
      | Positive i -> int_of_natplus i
      | Negative i -> - (int_of_natplus i);;
  
  let to_string x =
    string_of_int (to_int x);;

  (* Exercise: finish this! *)
end;;
