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 EAA05584; Sat, 31 Jan 2004 04:39:21 +0100 (MET) 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 EAA04082 for ; Sat, 31 Jan 2004 04:39:19 +0100 (MET) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i0V3dIv19329 for ; Sat, 31 Jan 2004 04:39:19 +0100 (MET) Received: from force.stwing.upenn.edu (root@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id i0V3dHiV018143 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Jan 2004 22:39:18 -0500 (EST) Received: from force.stwing.upenn.edu (wlovas@localhost [127.0.0.1]) by force.stwing.upenn.edu (8.12.10/8.12.9) with ESMTP id i0V3dGLN004956 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Jan 2004 22:39:17 -0500 (EST) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.12.10/8.12.9/Submit) id i0V3dGmv004954 for caml-list@inria.fr; Fri, 30 Jan 2004 22:39:16 -0500 (EST) Date: Fri, 30 Jan 2004 22:39:16 -0500 From: William Lovas To: caml-list@inria.fr Subject: Re: fancy types (was Re: [Caml-list] ocaml killer) Message-ID: <20040131033915.GA2151@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <40184A2F.6040007@dcs.qmul.ac.uk> <200401290000.i0T00ntl006988@bismarck-chet.watson.ibm.com> <40184FB9.4000808@dcs.qmul.ac.uk> <200401290034.i0T0Yutl009000@bismarck-chet.watson.ibm.com> <20040129162048.GA29094@force.stwing.upenn.edu> <401945DB.4030106@ps.uni-sb.de> <20040129191849.GA9427@force.stwing.upenn.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; lovas:01 wlovas:01 stwing:01 caml-list:01 2004:99 lovas:01 val:01 verbosity:01 ocaml:01 lisp:01 int:01 int:01 rec:01 rec:01 variant:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Jan 30, 2004 at 11:36:13AM +0100, Thomas Fischbacher wrote: > > On Thu, 29 Jan 2004, William Lovas wrote: > > > # type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b);; > > type ('a, 'b) specialist = S of (('a, 'b) specialist -> 'a -> 'b) > > # let fac n = > > let do_rec (S specialist) n = > > if n = 0 then > > 1 > > else > > n * specialist (S specialist) n > > in > > do_rec (S do_rec) n;; > > val fac : int -> int = > > Hm, correct me if I am wrong, but to me this looks as if you had to > unnecessarily cons at every recursive call... Well, it depends on what you mean by "unnecessarily" and what you mean by "cons". First, if by "cons" you mean "call a constructor", then yes, i did have to cons at every recursive call. However, if by "cons" you mean "allocate memory", i can't say for sure by looking at this code -- it says nothing about the optimizations applied to variant types during compilation or potential opportunities for structure sharing. I strongly suspect that memory need not be allocated, though, in which case the answer is no, i did not have to allocate memory at every recursive cell. As far as "unnecessarily" goes, to me the calls are perfectly necessary -- otherwise the code wouldn't make sense -- I think in types first and code second. :) So if efficiency is your concern, you've nothing to worry about. If its verbosity, then you have a fair argument -- you just have to weigh the development time benefits against the small amount of extra code you have to write beyond what LISP would require you to write. Personally, i think it's worth it, but that's just an opinion. cheers, William ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners