class type num = object method get_val : float method add : num -> unit method parse : string -> unit end class int = object val mutable x = 0 method get_val = float x method add : num -> unit = fun o -> x <- (int_of_float o#get_val) + x method parse s = x <- int_of_string s end class float = object val mutable x = 0. method get_val = x method add : num -> unit = fun o -> x <- o#get_val +. x method parse s = x <- float_of_string s end let parse s = let ret = if String.contains s '.' then (new float :> num) else (new int :> num) in ret#parse s; ret