From: Bardur A. <sp...@sc...> - 2006-06-16 14:30:29
|
Richard Jones wrote: > On Thu, Jun 15, 2006 at 04:46:03PM +0100, Amit Dubey wrote: >> I actually have similar code, but I tend to use it over floats more than >> ints. Maybe this calls for a functor-based design? > > I think it's a fine idea. Are there performance implications? For > reasons which I can't really fathom, functors don't seem to be fully > "inlined" when they are created, presumably resulting in extra > overhead. > Yup, I believe OCaml currently uses dynamic dispatch for functors. I don't think there are any theoretical reasons that this necessarily has to be the case. > What do other people think about the general concept? +1, I like it and I think it should be added to ExtLib. I've used similar code a number of times, but have used the code reuse technique known as Copy and Paste, just because I couldn't be bothered to package something up. Even though it may be a tad slower (no inlining), it does allow you to create Counters which count objects of an identical type *without* being "compatible". This allows a bit more type safety if you want it. Finally, I don't like the name Counter; it's a bit too generic for my tastes. Maybe call it Histogram instead? Cheers, -- Bardur Arantsson <bar...@TH...> "Mr. T to pity fool." http://www.theonion.com |