From: Alan P. <ap...@re...> - 2003-05-31 21:43:06
|
In article <Pin...@ea...>, Brian Hurt wrote: > > Sorry, I just had an epiphany on this issue. With enums we always have a > good count, right? I mean, we're not implementing my "-1 means we don't > know how many elements are in the enumeration". > > The enum code should use this and never cause an exception to be thrown. > Therefor it doesn't need to catch the exceptions either. > > let iter f e = > let c = e.count() in > for i = 1 to c do > f (e.next()) > done > > let fold f x e = > let rec loop c accu = > if c <= 0 then accu > else loop (c-1) (f (e.next ()) accu) > in > loop (e.count ()) x This undoes the lazy nature of Enum.filter, Enum.filter_map, and even more seriously, input_enum and input_char_enum. Basically, anywhere the code uses Enum.from will be a problem when relying on Enum.count. |