From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 041E0BB9C for ; Mon, 21 Nov 2005 09:48:23 +0100 (CET) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAL8mLZT001201 for ; Mon, 21 Nov 2005 09:48:22 +0100 Received: from localhost (moose-172 [172.16.254.3]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id jAL8m5jC024910; Mon, 21 Nov 2005 17:48:06 +0900 (JST) Date: Mon, 21 Nov 2005 09:48:01 +0100 (CET) Message-Id: <20051121.094801.126142370.garrigue@math.nagoya-u.ac.jp> To: mikelin@mit.edu Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] object constructor syntax compiler weirdness From: Jacques Garrigue In-Reply-To: <2a1a1a0c0511210009n24691c9eiad3046e4e0bce779@mail.gmail.com> References: <2a1a1a0c0511210009n24691c9eiad3046e4e0bce779@mail.gmail.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 438189D5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 syntax:01 compiler:01 mikelin:01 syntax:01 3.08.4:01 endline:01 endline:01 parentheses:01 radius:98 radius:98 constructor:01 constructor:01 functions:01 jacques:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 From: Mike Lin > The following are by no means common or advisable syntax, but I was > curious if there is a rationale behind why certain things are syntax > errors or not. I'm using 3.08.4 -- apologies if this was fixed or > modified in 3.09. I have no rationale, but at least I can explain. > class circle radius = > let pi = 3.14159 in > object > method area = pi *. radius *.radius > end > > >> fine > > class circle2 radius = > let pi = 3.14159 in > print_endline "Creating a circle"; > object > method area = pi *. radius *.radius > end > > >> syntax error The things you are able to write in the prefix of a class constructor are more limited than in normal functions. In the above case, I would say that it would be a bit confusing. You can of course write it let () = print_endline "Creating a circle" in object ... end Another thing you cannot write is class ... = let module M = ... in object ... end. In that cases there are difficulties related to mixing module scope with class definitions (which have there own notion of scope), making it rather difficult to introduce it. > Most curiously: > > class circle3 radius = > let pi = 3.14159 in > (object > method area = pi *. radius *.radius > end) > > >> fine > > class circle4 radius = > let pi = 3.14159 in > begin > object > method area = pi *. radius *.radius > end > end > > >> syntax error Parentheses in class definitions are useless, so there is no reason to add a begin .. end construct. I suppose that the first syntax is only allowed as a degenerated case of class c = (object ... end : ct) Jacques Garrigue