Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: [Caml-list] functors with style?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-11-20 (20:01)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] functors with style?
On Mon, 19 Nov 2001, Shivkumar Chandrasekaran wrote:
> On Monday, November 19, 2001, at 10:32 AM, Krishnaswami, Neel wrote:
> > A functor is compiled to what is essentially a function that
> > takes a record as an argument (the module it receives as an
> > argument), and returns a record of functions and values. So
> > code generation happens only once for each functor, and each
> > functor application takes a very small amount of memory at
> > link time.
> Which of course is a problem at the "small-scale". For example I would 
> like to develop a functor that is generic over the representation of 
> reals (float32_elt, float64_elt, fixed_point, etc.). But now if I 
> instantiate it for float64_elt and do arithmetic over float64_elt even 
> simple operations will be looked-up at run-time leading to a terrible 
> performance loss.

Indeed, I find that this very issue has annoyed me for many years. When I 
first started playing with C++ I was involved in scientific computing and 
I was less interested in the OO features than I was in overloading,
templates, and operator redefinition. I'd actually prefer the C++ style 
expansion in the case you describe above, and in many others. 

The other issue I have with functorial programming is the inability to
have types and functor applications in a recursive relationship, but this 
is a well known problem and I think people at INRIA are working on it.

> Ideally I would prefer it if the compiler allowed the programmer to 
> decide which functor applications lead to compile-time code generation 
> and which are through dictionary-passing.

There's also an evil fact that's unkown to many people, namely that 
DEC^H^H^HCompaq^H^H^H^H^H^H, ummm, HP?, has a patent which may cover 
some helpful techniques. DEC had implemented their own Ada 83 compiler, 
and, unlike C++ templates, Ada generics can be implemented by sharing as
well as by "macro expansion", and some of the DEC implementors had
patented a scheme which did both sharing and expansion. I'm not sure if 
this matters, but I can try and find the reference if anyone is really

-- Brian
Bug reports:  FAQ:
To unsubscribe, mail  Archives: