From: Brian H. <bh...@sp...> - 2003-10-06 22:04:02
|
On Mon, 6 Oct 2003, Nicolas Cannasse wrote: > > 2) The next function returns 'a and throws an execption to indicate the > > end of elements in one place, and returns 'a option and returns None to > > indicate the end of elements in another. > > Your eternal battle here :) > Not yet convinced that exceptions are better - faster - for internal usage, > but dangerous for the programmer if raised from the API ? > BTW, there is no Enum.next in the API : it's called Enum.get Until I can come up with something better, I'm not going to restart the debate. > Your answer here : > > class virtual ['a] enum = object > method virtual map : 'b . ('a -> 'b) -> 'b enum > end I tried that. No dice: $ ocaml Objective Caml version 3.07 # class virtual ['a] enum = object method virtual map : 'b . ('a -> 'b) -> 'b enum -------------------------- end;; This type scheme cannot quantify 'b : it escapes this scope. # > > BTW, objects are certainly the worst part of OCaml. They are tricky, > difficult to use, and have bad performances (compared to modules instances). > If you look at Java programmers (or most of the OO programmers actually) > they're using OO only for prototyping ( interfaces in Java or pure virtual > classes in C++ ). In Ocaml , you can already prototype by using a module and > add specialisation with some polymorphic closures. Believe me : you don't > need objects. While I'll agree that Java programmers use objects for a lot of things that Ocaml has better ways of doing, I think objects are the *natural* representation for enumerations. You have internal state shared among multiple functions (data hiding), multiple implementations of the same methods (inheritance), and a specified contract for the API (interfaces). This is OO all over. Brian |