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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 84C0EBB84 for ; Tue, 1 Jul 2008 17:07:37 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.27,732,1204498800"; d="scan'208";a="12719635" Received: from arvin.irisa.fr (HELO [131.254.11.86]) ([131.254.11.86]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Jul 2008 17:07:37 +0200 Message-ID: <486A4703.6040505@irisa.fr> Date: Tue, 01 Jul 2008 17:02:27 +0200 From: Tiphaine Turpin User-Agent: Thunderbird 1.5.0.10 (X11/20070303) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Open class types References: <486A36DE.4040605@stork.ru> In-Reply-To: <486A36DE.4040605@stork.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; irisa:01 compiler:01 restrictive:01 bug:01 mli:01 beginner's:01 ocaml:01 bug:01 .....:98 beginners:01 inline:01 inline:01 caml-list:01 caml-list:01 int:01 The behaviour of the compiler for your code is strange: I don't see why the message error say the following: #session_t as 'a = < id : int; location : 'b. #location_t; .. > where location is required to be a #location_t for all 'b (which I assume is the implicit self type variable of the open_type #location_t). This seems to restrictive. Maybe a bug ? Anymay, putting an explicit parameter in the session_t type solves the issue: class type ['a] session_t = object method id:int method location: #location_t as 'a end let check_session (session:'a #session_t) = begin print_int session#id; print_int session#location#a; print_string session#location#b end Tiphaine Turpin SerP a écrit : > > > class type location_t = > object > method a: int; > method b: string; > end; > > class type session_t = > object > method id:int; > method location: #location_t; > end; > > value check_session (session:#session_t) = begin > print_int session#id; > print_int session#location#a; > print_string session#location#b; > end; > > class location = > object > method a = 1; > method b = "b"; > method c = ["a";"b"]; > end; > > class session = > object value location = new location; > method id = 1; > method location = location; > end; > > value _ = > let s = new session in > check_session s; > ==================================== > Error: This expression has type session = < id : int; location : > location > > but is here used with type > #session_t as 'a = < id : int; location : 'b. #location_t; .. > > Type location = < a : int; b : string; c : string list > > is not compatible with type 'b > The second object type has no method c > -------------------------------------------- > But, > value check_session (session:< id : int; location : < a : int; b : > string; .. >; .. >) = begin ..... > > Compiled properly. > > Please help. Is exists any way to define open class type like inline > type definition. > Write every function with inline type definition in mli files is > terrible. > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >