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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 3EC9FBC57 for ; Sun, 28 Mar 2010 21:20:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQBAL5Ir0vUNQVcmWdsb2JhbACPQYtnFQEBAQEBBg0KBxEivGGFAQQ X-IronPort-AV: E=Sophos;i="4.51,323,1267398000"; d="scan'208";a="59835370" Received: from postbode02.versateladsl.be ([212.53.5.92]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Mar 2010 21:20:46 +0200 Received: (qmail 5141 invoked by uid 0); 28 Mar 2010 19:20:47 -0000 Received: from unknown (HELO poincare.swapping.umh.ac.be) ([94.109.149.235]) (envelope-sender ) by smtp.versateladsl.be (qmail-ldap-1.03) with SMTP for < >; 28 Mar 2010 19:20:47 -0000 Received: from [127.0.0.1] (helo=localhost ident=trch) by poincare.swapping.umh.ac.be with esmtp (Exim 4.71) (envelope-from ) id 1Nvy2F-00018p-T6; Sun, 28 Mar 2010 21:20:35 +0200 Date: Sun, 28 Mar 2010 21:20:35 +0200 (CEST) Message-Id: <20100328.212035.735321043546824606.Christophe.Troestler+ocaml@umons.ac.be> To: steph@glondu.net Cc: darioteixeira@yahoo.com, caml-list@yquem.inria.fr Subject: Re: [Caml-list] Structural subtyping problem From: Christophe TROESTLER In-Reply-To: <4BAF92B5.1060502@glondu.net> References: <61102.44294.qm@web111503.mail.gq1.yahoo.com> <4BAF92B5.1060502@glondu.net> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons Return-Receipt-To: Christophe.Troestler@umons.ac.be Disposition-Notification-To: Christophe.Troestler@umons.ac.be X-Mailer: Mew version 7.0.50 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; subtyping:01 christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0200,:01 bool:01 bool:01 recursive:01 sig:01 val:01 val:01 struct:01 imho:01 Hi, On Sun, 28 Mar 2010 19:32:37 +0200, Stéphane Glondu wrote: > > type steps = { > step1 : 'a. ?story:( as 'a) -> unit -> bool; > step2 : string -> bool; > step3 : 'a. story:(<title : string; count : int; ..> as 'a) -> bool > } > > let rec steps = { [...] IMHO, recursive modules are also a nice way to achieve the same effect : module rec X : sig val step1 : ?story:<title : string; ..> -> unit -> bool val step2 : string -> bool val step3 : story:<title : string; count : int; ..> -> bool end = struct let rec step1 ?story () = match story with | Some s -> X.step2 s#title | None -> X.step2 "title1" and step2 title = let story = object method title = title method count = 0 end in X.step3 story and step3 ~story = match story#count with | 0 -> X.step1 ~story () | 1 -> let story = object method title = "title2" end in X.step1 ~story () | _ -> true end My 0.02¤, C.