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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 1C68CBBAF for ; Wed, 8 Apr 2009 02:38:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai8GAMaO20nZSMDdZGdsb2JhbACBUpRaCwMODwW2Y4N7Bg X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="27249206" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail1-smtp-roc.national.inria.fr with ESMTP; 08 Apr 2009 02:38:52 +0200 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate01.web.de (Postfix) with ESMTP id 5E828FF8EE29 for ; Wed, 8 Apr 2009 02:38:52 +0200 (CEST) Received: from [78.43.226.218] (helo=frosties.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1LrLoa-0000tl-00 for caml-list@inria.fr; Wed, 08 Apr 2009 02:38:52 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1LrLoZ-0001O4-8v for caml-list@inria.fr; Wed, 08 Apr 2009 02:38:51 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Subject: Re: [Caml-list] Subtyping References: <873aclf1z8.fsf@frosties.localdomain> Date: Wed, 08 Apr 2009 02:38:49 +0200 In-Reply-To: <873aclf1z8.fsf@frosties.localdomain> (Goswin von Brederlow's message of "Tue, 07 Apr 2009 07:48:43 +0200") Message-ID: <87bpr86kti.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/tRKuJKz7QuWOCet4FQ6kBPu5aw6hPiooeyNx6 x7qup6pilhi2z0tz0Gfbxlku4oHfmfXI6C6ePJBY7RKn7AITQI io5tAlUnk= X-Spam: no; 0.00; subtyping:01 foo:01 foo:01 ocaml:01 ocaml:01 iter:01 syntax:01 1.2:98 mfg:98 abstract:01 caml-list:01 int:01 int:01 writes:01 newline:02 Goswin von Brederlow writes: > So what other ways are there of doing this? Records. Idealy I would > like to do this: > > type base = { x : int } > let make_base x = { x = x } > let print_x r = print_int r.x > type foo = { base with y : int } > let make_foo x y = { x = x; y = y } > let _ = > print_x (make_base 0); print_newline (); > print_x (make_foo 0 1); print_newline ();; > > Ocaml has no way of making this work like that, right? Small extra question concerning this. Can I get ocaml to recognise a type like this? type base = 'a. { x : 'a; fn : 'a -> unit; } List.iter (fun r -> r.fn r) [{x = 1; fn = (fun r -> print_int r.x); }; {x = 1.2; fn = (fun r -> print_float r.x); }] The difference to a "'a base" type would be that the 'a is only infered and fixed inside the record but remains abstract outside of it. For that reason this would not be allowed: let cross_call x y = x.fn y The 'a would have to escape the record which wouldn't be allowed. So is there any syntax or trick to get the ocaml typesystem to construct such a type? MfG Goswin