From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pA4D98Jl032439 for ; Fri, 4 Nov 2011 14:09:08 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlkDACvjs06Bu/5qlGdsb2JhbABEmlOPOSIBAQEBCQsJCRQEIYIrAYEVC00qG50FoBCJKwSmAw X-IronPort-AV: E=Sophos;i="4.69,455,1315173600"; d="scan'208";a="128399320" Received: from mailrelay1.lrz-muenchen.de ([129.187.254.106]) by mail1-smtp-roc.national.inria.fr with ESMTP; 04 Nov 2011 14:09:03 +0100 Received: from webmail.mwn.de ([129.187.254.85] [129.187.254.85]) by mailout.lrz-muenchen.de with ESMTP for caml-list@inria.fr; Fri, 4 Nov 2011 14:06:23 +0100 Received: from webprx1.audi.de ([143.164.102.13]) (SquirrelMail authenticated user weissmam) by webmail.mwn.de with HTTP; Fri, 4 Nov 2011 14:06:23 +0100 (CET) Message-Id: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de> Date: Fri, 4 Nov 2011 14:06:23 +0100 (CET) From: Markus =?iso-8859-1?Q?Wei=DFmann?= To: caml-list@inria.fr User-Agent: SquirrelMail/1.4.13 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: [Caml-list] elegant subtyping? 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