On 11/30/05, Björn Hägglund <[EMAIL PROTECTED]> wrote:
At this point, you may wonder why the ADT is not packaged as a functor? I
would really like to do that! But as far as I understand Mozart, it does not
seem possible to instantiate functors with an argument (such as the
PriorityOf fed to NewPQ). If someone knows how to do this elegantly, please
let me know.

It seems to me that a functor would actually be *less* elegant, because then every time you wanted one you'd have to call Module.apply (which makes me worry about the overhead of creating the ModuleManager each time). At one point I was looking for the Mozart equivalent of a C++ structs (attributes accessible with the dot operator, but not mutable unless I say they are) and considered using a functor plus an "Init" method if input parameters needed to be passed in.

functor PQMaker...
end

[PQ] = {Module.apply [PQMaker]}
PQ.PriorityOf = fun {$ A} A.priority end    % This priority queue relies upon all objects being unioned having a priority feature...

Of course, if you want to be elegant you could just create the functor on the fly...

fun {PQMaker PriorityOf}            % pass in some sort of comparator function for unions
   functor $...
      fun {Union A B}
       ...
         if {PriorityOf X} < {PriorityOf Y} then...
     
[PQ] = {Module.apply [{PQMaker fun{$ A} A.priority end }]} % create a new priority queue bound to this particular Priority function

Ultimately, though, I don't think functors are the way to go for making objects. I'm too worried about overhead, and functors don't really seem to be designed for creating objects so much as modules.

Max Wilson

--
Be pretty if you are,
Be witty if you can,
But be cheerful if it kills you.
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to