On Fri, 2004-05-28 at 11:56, Brian Hurt wrote:
> > (1) Move 'count()' up with the iterators.
> > Count is specified to consume the enumeration.
> > It doesn't actually have to.
> > The current implementation is unchanged.
>
> This is totally worthless. "this is how many items I just threw
> away".
Yes, that's what it does, but it isn't worthless.
If the enumeration is forward, you can use a copy
of it, which has not been consumed.
If the enumeration is input, it makes no difference
whether it is worthless or not because there is no
other way to count such an enumeration than
permanently consume it.
Counting the number of lines in a file isn't
entirely worthless .. unix wc does it :)
> Try these semantics on for size: instead of fast_count, you get a
> has_count, which returns true if the enumeration has a count, false
> otherwise. If the enumeration does not have a count, it returns -1. In
> any case, count is gaurenteed to be no worse than O(n) cost.
> It is gaurenteed that Enum.to_list works without a count, so if you
> absolutely need a count and can not do without it (like Enum.to_array),
> you first convert the the enum to a list, and then get the count on the
> list and go from there. If you do not absolutely need a count but can
> find one usefull (like dynarray or extMap), then the function can exhibit
> different behavior if a count exists or not- for example, a function can
> be O(n) if a count exists, or O(n log n) if it doesn't.
What I'd like to do is eliminate dynamic behaviour.
I hate fast_count for that reason. I'd like to move
more of the semantics into the static typing.
C++ has no problem with this, although the type check
doesn't happen until link time which is a pain.
True, we should not copy the C++ technique for doing it.
But anyhow my goal is to try and build a more static
model of the forward/input iterator distinction.
The reason is the same as why we all love Ocaml
FP in the first place: the ability to actually reason
about your code.
--
John Skaller, mailto:skaller@xxxxxxxxxxxx
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
|