From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 6A11BBBAF for ; Mon, 6 Apr 2009 11:55:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgQGACJu2UnZSMDdZmdsb2JhbACBUpRUDQsDBQkPBbF8hA8G X-IronPort-AV: E=Sophos;i="4.39,329,1235948400"; d="scan'208";a="24034987" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Apr 2009 11:55:17 +0200 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate01.web.de (Postfix) with ESMTP id 72C88FF76395; Mon, 6 Apr 2009 11:55:16 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1LqlXw-0004Cc-00; Mon, 06 Apr 2009 11:55:16 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1LqlXv-0001kT-KK; Mon, 06 Apr 2009 11:55:15 +0200 From: Goswin von Brederlow To: Zheng Li Cc: Jacques Garrigue , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Instance variables can't be polymorphic? {a few more annoyances on "val" syntax} References: <49D93BB3.501@users.sourceforge.net> <20090406.124055.116565018.garrigue@math.nagoya-u.ac.jp> <49D9BED7.4000201@users.sourceforge.net> Date: Mon, 06 Apr 2009 11:55:15 +0200 In-Reply-To: <49D9BED7.4000201@users.sourceforge.net> (Zheng Li's message of "Mon, 06 Apr 2009 10:35:35 +0200") Message-ID: <878wme9ke4.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.21 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+AirfjCnN7YuW5gzivtdqErHi9UPx8+ykJXHmq lQNIvz/WcpwvyUOixBwve2OnvQw3xxg8HLqR5NlWjPjnm0Kowi vm7Ob+4Gs= X-Spam: no; 0.00; val:01 syntax:01 syntax:01 ocaml:01 val:01 semantics:01 foo:01 decr:01 foo:01 decr:01 recursion:01 ocaml:01 subtype:01 functors:01 mfg:98 Zheng Li writes: > [OT]: Here are a few more annoyances on the syntax of instance > variable I've encountered. I recorded it here for comments: > > Why it can't just copy the common "let" syntax in OCaml? Even though > it's possible to just lift the awkward "val" definitions out of > objects and using "let" instead, I'm really uncomfortable when being > forced to do that. Besides, the lifted variables won't be accessible > through inheritance any more, so they are not strictly equivalent or > interchangeable in semantics. > > Currently, the "val" syntax > > - doesn't support pattern matching assignment. Instead of > -- > let a,b,c,d = tuple4 > -- > one write > -- > val a = match tuple4 with a,_,_,_ -> a > val b = match tuple4 with _,b,_,_ -> b > val c = match tuple4 with _,_,c,_ -> c > val d = match tuple4 with _,_,_,d -> d > -- > This is still the easy case, image if your pattern matching will > also trigger some side-effect. class foo = let (a,b,c,d) = tuple4 in object val a = a val b = b val c = c val d = d end > - doesn't support sharing state. > -- > let up,down = > let r = ref 0 in > (fun () -> incr r; !r), > (fun () -> decr r; !r) > -- > can't be expressed directly as instance variables Same thing. Use let to create the shared state and then assign in the object. Although that really ought to be written as class foo : object (* to hide count if you really want that *) method private up : unit method private down : unit end = object val count = ref 0 method private up = incr count method private down = decr count end > - doesn't support shortcut syntax of function definition like > -- > val f x y z = x + y + z > -- > instead one must write > -- > val f = fun x y z -> x + y + z > -- same > - doesn't support recursion. Instead of > -- > val rec fact n = > if n <= 1 then 1 else n * fact (n-1) > -- > one must write > -- > val fact = > let rec fact_rec n = > if n <= 1 then 1 else n * fact_rec (n-1) in > fact_rec > -- same > - all parallel assignments, no assignment orders, hence can't refer to > previous assignment > > -- > val x = 3 > val y = x + 11 > -- > > is wrong, even if it makes perfect sense in many situations. To access > "x", one is simply forced to declare "y" as method! same again. > Any comments? Yes, ocaml objects can drive one nuts. :) You seem to want to use classes with static functions (functions that do not have/use self). Why not use records? Is that just because you can not coerce record to a "subtype"? Sometimes one can use modules and functors instead of objects. MfG Goswin