From: Brian H. <bh...@sp...> - 2003-10-06 17:01:25
|
On 6 Oct 2003, skaller wrote: > On Sun, 2003-10-05 at 19:59, Nicolas Cannasse wrote: > > Hi people ! > > > > Right now, SF downloads are showing that there is (only) around 60 peoples > > that downloaded the ExtLib (no counts on how many are actually using it :-). > > Well, I'm concerned still with the semantics of Enum, > and since Enum-extending other data structures is a key > feature .. I agree. My laundry list of things I don't like about the current enum implementation: 1) Creating new enums is clumsy. 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. 3) Next both returns the "current" element and moves the enumeration forward to the next element. These two different operations should be seperate functions. 4) Imperitive/side effect driven. Given a choice, I prefer functional semantics. Note that you can still do enumerations of imperitive functions (like reading a file). What you do is cache the next object, making a "pseudo-functional" enumeration object. If it's already returned a next enum, you return the cached value. If it hasn't, it creates a next element, caches it, and returns it. Effectively, the enumerations become a singly linked list. I came up with a brilliant solution to all the of above, based upon objects and inheritance (IMHO an enumeration is an object). Unfortunately, I needed the following class to be typeable in Ocaml: class virtual ['a] enum = object method virtual map: ('a -> 'b) -> 'b enum end;; Unfortunately, this doesn't work (in 3.06 or 3.07). Not being able to do this, my next best solution meant every time you called step (to move the enumeration forward) on an enumeration that had been mapped n times, you needed to create n+1 new objects, and calling current (to return the current element) you needed to create n option variables. Which is why I haven't posted the code to the list :-). Brian |