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 SAA18125; Wed, 8 Oct 2003 18:25:26 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA18352 for ; Wed, 8 Oct 2003 18:25:24 +0200 (MET DST) Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h98GPO101663 for ; Wed, 8 Oct 2003 18:25:24 +0200 (MET DST) Received: from PWARP (unknown [81.56.197.80]) by postfix3-2.free.fr (Postfix) with SMTP id 61F1CC281; Wed, 8 Oct 2003 18:25:23 +0200 (CEST) Message-ID: <010a01c38db8$c30c7be0$6f01a8c0@PWARP> From: "Nicolas Cannasse" To: "Serge" , References: Subject: Re: [Caml-list] Constructors as functions and tuples in constructors Date: Wed, 8 Oct 2003 18:25:17 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 generality:01 alloc:01 alloc:01 indirection:01 cannasse:01 ints:01 nicolas:01 nicolas:01 int:01 int:01 constructors:01 constructors:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Gentlemen! > > There are two features, which might it be useful to support in the > language w/out modifying it much. And they both are about greater > generality of the language. > > First, it would be nice to have constructors as functions like below: > > List. map Some [17] This is only syntaxic sugar. First class constructors are easy to add to the language, that's just a matter of will from the INRIA team to choose to add it or not ( meaning : since they didn't put the feature in the language yet, they might have good reasons to do so. ). > Second, it would also be nice not to have "the concept of constructor > arity", and treat the code below as correct: > > type t = A of int * int > let _ = > match A (17, 0) with > A z -> match z with (x, y) -> () > > Does anybody know, whether this is possible? Or, if not, what are the > prohibiting reasons? This is possible : type t = A of (int * int) Notice the difference : - in the first case, you alloc a block with tag "A" of size 2 - in the second, you alloc a block with tag "A" of size 1 containing a tuple (a block of size 2 with tag 0 containing the two ints). There is then one more indirection in your integers access but the tuple can be returned directly without any added allocation. Nicolas Cannasse ------------------- 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