From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA31046; Fri, 27 Jul 2001 16:11:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA31073 for ; Fri, 27 Jul 2001 16:11:31 +0200 (MET DST) Received: from fichte.ai.univie.ac.at (fichte.ai.univie.ac.at [131.130.174.156]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f6REBTr22004; Fri, 27 Jul 2001 16:11:29 +0200 (MET DST) Received: from kastanie.ai.univie.ac.at (root@kastanie.ai.univie.ac.at [131.130.174.141]) by fichte.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id QAA03493; Fri, 27 Jul 2001 16:11:29 +0200 Received: (from markus@localhost) by kastanie.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) id QAA03013; Fri, 27 Jul 2001 16:09:55 +0200 Date: Fri, 27 Jul 2001 16:09:55 +0200 From: Markus Mottl To: Xavier Leroy Cc: caml-list@inria.fr Subject: Re: [Caml-list] Module (re)construction cost Message-ID: <20010727160955.A2756@kastanie.ai.univie.ac.at> References: <20010722101845.A31393@localhost.localdomain> <20010727152521.A28238@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010727152521.A28238@pauillac.inria.fr>; from Xavier.Leroy@inria.fr on Fri, Jul 27, 2001 at 15:25:21 +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 27 Jul 2001, Xavier Leroy wrote: > > i.e. does functor > > application cost anything (time ? memory ?). > > Evaluating the functor application itself is very cheap, it just > builds a tuple of values from a tuple of values. Moreover, this takes > place at program start-up time, i.e. not often. The main hidden cost > is the lack of optimization in certain function calls as described > above. Unless this functor application is used to create a local module, of course. Then each call to the enclosing function (and if control flow actually reaches the functor application) will require the creation of this tuple. It should also be noted that this may mean evaluating possibly expensive expressions whose values will be put into the tuple slots. In fact, you could even have expressions there that do not terminate at all or eat up all your memory depending on the parameters passed via the functor parameter. E.g.: module type VICE = sig val sleep : bool val munch : bool end module Make (Vice : VICE) = struct let _ = if Vice.munch then let stomach = ref [] in for i = 1 to 10000000 do stomach := () :: !stomach done; if Vice.sleep then while true do () done end let sin sleep munch = let module Immoderateness = struct let munch = munch let sleep = sleep end in let module Cockaigne = Make (Immoderateness) in () let _ = sin true true First the functor application will eat a good share of your memory. Then it will put your machine to sleep forever... Regards, Markus Mottl -- Markus Mottl markus@oefai.at Austrian Research Institute for Artificial Intelligence http://www.oefai.at/~markus ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr