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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D65DEBC69 for ; Fri, 3 Aug 2007 23:18:45 +0200 (CEST) Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [192.109.42.8]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l73LIiQo004398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 3 Aug 2007 23:18:45 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id l73LIfma008735 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 3 Aug 2007 23:18:41 +0200 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id l73LIfQa008733 for caml-list@inria.fr; Fri, 3 Aug 2007 23:18:41 +0200 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-073-105-032.pools.arcor-ip.net (dslb-088-073-105-032.pools.arcor-ip.net [88.73.105.32]) by webmail.in-berlin.de (IMP) with HTTP for ; Fri, 3 Aug 2007 23:18:41 +0200 Message-ID: <1186175921.46b39bb1508b1@webmail.in-berlin.de> Date: Fri, 3 Aug 2007 23:18:41 +0200 From: Oliver Bandel To: caml-list@inria.fr Subject: Type notation in OO-layer MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Miltered: at discorde with ID 46B39BB4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bandel:01 in-berlin:01 notation:01 notation:01 ocaml:01 val:01 mutable:01 printf:01 sprintf:01 printf:01 sprintf:01 endline:01 endline:01 ocaml:01 ocamlc:01 Hello, please look at this very simple OO-stuff to discuss a question I have, regarding the notation (and / or behaviour) of the OO-layer in OCaml: ======================================================= oliver@siouxsie2:~/ocaml-oo$ cat verysimple.ml class simple_1 = object val mutable mutval = 12 method get = mutval method set x = mutval <- x method value_as_string = Printf.sprintf "value_as_string: %d" mutval method vas () = Printf.sprintf "vas: %d" mutval end let iprint i = Printf.printf "iprint: %d\n" i let example_s1 = new simple_1 let _ = let o_1 = new simple_1 in iprint (o_1 # get); print_endline (o_1 # value_as_string); print_endline (o_1 # vas()); o_1#set 77; iprint (o_1 # get); print_endline (o_1 # value_as_string); print_endline (o_1 # vas()); () oliver@siouxsie2:~/ocaml-oo$ ocaml verysimple.ml iprint: 12 value_as_string: 12 vas: 12 iprint: 77 value_as_string: 77 vas: 77 oliver@siouxsie2:~/ocaml-oo$ ocamlc -i verysimple.ml class simple_1 : object val mutable mutval : int method get : int method set : int -> unit method value_as_string : string method vas : unit -> string end val iprint : int -> unit val example_s1 : simple_1 oliver@siouxsie2:~/ocaml-oo$ ======================================================= As you can see, the methods "value_as_string" and "vas" are intended to do the same: giving back a string, that will be created from the internal int-value. Following the non-OO programming in OCaml, vas() should be the right way to do it, because the method get's no arg. Following the OO-like way, value_as_string should be OK also. What would be the right way? value_as_string has type "string", but that is not completely correct, because it get's no input-value, and therefore is of type "unit -> string". One could say, that this is a special notation for OO, but if we are rigid (we should be! ... shouldn't we?!) it is not correct. As it is not a true "unit"-function, we at least should give it a unit-like type like "message -> string" so that the type-system make a complete annotation of type?! Why is the "sending a message to the method" activity not notated in the type? And: are both definitions correctly? Which to choose? Preferences in style? TIA, Oliver