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 BCC9DBB9C for ; Mon, 19 Sep 2005 22:58:32 +0200 (CEST) Received: from mail.gmx.net (mail.gmx.de [213.165.64.20]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j8JKwW1R020503 for ; Mon, 19 Sep 2005 22:58:32 +0200 Received: (qmail invoked by alias); 19 Sep 2005 20:58:31 -0000 Received: from p54A30669.dip0.t-ipconnect.de (EHLO [192.168.2.136]) [84.163.6.105] by mail.gmx.net (mp005) with SMTP; 19 Sep 2005 22:58:31 +0200 X-Authenticated: #20477425 From: Michael Wohlwend To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Request for example where type annotation are required Date: Mon, 19 Sep 2005 22:59:36 +0200 User-Agent: KMail/1.8 References: <432F1DC5.2000607@univ-savoie.fr> In-Reply-To: <432F1DC5.2000607@univ-savoie.fr> X-Face: S)[vu%Bha1d&ej9GfwAq~7C}A,y[B.uS}+D6'hb~xPwsxymw$fnCOaMe<=?utf-8?q?*bnUajSBR=5Fm=3FR=0A=09?=@V3;iX8[A}z`.%pEQ1r7iZhN8#ktTCBQ}&mkx>=RH&l|l6\]NZI@ MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509192259.36586.micha-1@fantasymail.de> X-Y-GMX-Trusted: 0 X-Miltered: at nez-perce with ID 432F2678.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 annotation:01 christophe:01 raffalli:01 variants:01 ocaml:01 val:01 mutable:01 allways:01 val:01 mutable:01 'a-:01 ...:98 wrote:01 node: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.1 required=5.0 tests=FORGED_RCVD_HELO,SPF_FAIL autolearn=disabled version=3.0.3 On Monday 19 September 2005 22:21, Christophe Raffalli wrote: > I am looking for small ML examples (using variants, modules, objects, > etc ...) > Where one needs to write type information to be able to type-check the > program with OCaml As my example, this should be a try of linked objects (like dllist od extlib): class ['a] node = object(self:'a) val mutable nx = nil method next = nx method set_next n = nx <- n method apply f upto = f self; if self <> upto then self#next#apply f upto end;; it doesn't work; the problem is the "nil" objects to initalize it, i cannot get this right, there are allways typing errors. Can this be defined without type-annotations? ahem, this one works easily :-) class ['a] node = object(self:'a) val mutable nx =(Obj.magic 0 : 'a) method next = nx method set_next n = nx <- n method apply (f: 'a->unit) upto = f self; if self <> upto then self#next#apply f upto initializer nx <- self end;; let a = new node;; ------------------------------------------------------------- Michael