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 pA4DRYLf001429 for ; Fri, 4 Nov 2011 14:27:38 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIGAKHns06CiAFmgWdsb2JhbABEmlOOGYEgIgEBFiYlgXIBAQUyAQVAEQshFg8JAwIBAgFFEwgBAReHb7UkiSsEpgM X-IronPort-AV: E=Sophos;i="4.69,455,1315173600"; d="scan'208";a="116922500" Received: from leb.cs.unibo.it ([130.136.1.102]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 04 Nov 2011 14:27:37 +0100 Received: from ssl.cs.unibo.it (ssl.cs.unibo.it [127.0.0.1]) (Authenticated sender: hidden) by leb.cs.unibo.it (Postfix) with ESMTPSA id 84EC42495 for ; Fri, 4 Nov 2011 14:27:37 +0100 (CET) Message-ID: <4EB3E848.2010508@cs.unibo.it> Date: Fri, 04 Nov 2011 14:27:36 +0100 From: Matthias Puech User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: caml-list@inria.fr References: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de> In-Reply-To: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] elegant subtyping? Isn't that exactly what polymorphic variants are for? http://caml.inria.fr/pub/docs/manual-ocaml/manual006.html#toc36 Cheers, -m Le 11/04/2011 02:06 PM, Markus Weißmann a écrit : > 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 >