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
-- 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
