spacepaste

  1.  
  2. open Batteries
  3. class type number = object ('a)
  4. (* method plus: 'a -> 'a *)
  5. end
  6. class int_wrap (i: int) = object
  7. val i = i
  8. end
  9. class float_wrap (f: float) = object
  10. val f = f
  11. end
  12. let parse: string -> number = fun s ->
  13. if String.exists s "." then
  14. float_of_string s |> new float_wrap
  15. else
  16. int_of_string s |> new int_wrap
  17.