From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA4DiGp6002267 for ; Fri, 4 Nov 2011 14:44:16 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AigDAB/rs06GnQCBkGdsb2JhbABEmh80jhmBICIBAQEBBwsNBxQDIoFyAQEFMgEgGxsLGA0aBxQYGQEqEgmHb7Ueg0eFAWMEpgM X-IronPort-AV: E=Sophos;i="4.69,455,1315173600"; d="scan'208";a="116926004" Received: from shiva.jussieu.fr ([134.157.0.129]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 04 Nov 2011 14:44:10 +0100 Received: from hydrogene.pps.jussieu.fr (hydrogene.pps.jussieu.fr [134.157.168.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id pA4DhieA040106 for ; Fri, 4 Nov 2011 14:43:57 +0100 (CET) X-Ids: 168 Received: by hydrogene.pps.jussieu.fr (Postfix, from userid 2065) id 19390C12EE; Fri, 4 Nov 2011 14:43:43 +0100 (CET) Date: Fri, 4 Nov 2011 14:43:43 +0100 From: Pietro Abate To: caml-list@inria.fr Message-ID: <20111104134342.GA9248@pps.jussieu.fr> References: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de> X-Operating-System: GNU/Linux User-Agent: Mutt/1.5.20 (2009-06-14) X-Miltered: at jchkmail.jussieu.fr with ID 4EB3EC10.003 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 4EB3EC10.003/134.157.168.1/hydrogene.pps.jussieu.fr/hydrogene.pps.jussieu.fr/ Subject: Re: [Caml-list] elegant subtyping? hello, using polymorphic variants maybe ? # module Cfg = struct type statement = [ `Assign | `Guard ] end;; module Cfg : sig type statement = [ `Assign | `Guard ] end # module Ast = struct type statement = [ Cfg.statement | `Goto | `Label ] end;; module Ast : sig type statement = [ `Assign | `Goto | `Guard | `Label ] end p On Fri, Nov 04, 2011 at 02:06:23PM +0100, Markus Weißmann wrote: > Hello everyone, > > I'm writing on a compiler and want to subtype the "statements" that can > occur in my code: > At first I have an abstract syntax tree that can hold any statement of the > language. From that I create a control flow graph that will only have > non-control-flow statements (a true subset of the Ast-statements). > Whats the best way to realize that? > > Basically I have: > > module Ast: type statement = Assign | Guard | Goto | Label > module Cfg: type statement = Assign | Guard > > > I see three -- not so elegant -- solutions to this: > > 1.) type-safe but imho quite ugly code: > module Cfg: type statement = Assign | Guard > module Ast: type statement = Base of Cfg.statement | Goto | Label > > 2.) use the same type for both and give up the safety that wrong types > cannot show up in the Cfg > > 3.) use objects > > Did I miss the type-safe, elegant, module-based solution somehow? Or is > 1.) as good as it gets? > > > Best regards > > -Markus > > -- > Markus Weißmann, M.Sc. > Institut für Informatik > Technische Universität München > Raum 03.07.054, Boltzmannstr. 3, 85748 Garching > > Tel. +49 (89) 2 89-1 81 05 > Fax +49 (89) 2 89-1 81 07 > > mailto:markus.weissmann@in.tum.de > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs -- ---- http://en.wikipedia.org/wiki/Posting_style