caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] elegant subtyping?
@ 2011-11-04 13:06 Markus Weißmann
  2011-11-04 13:27 ` Matthias Puech
  2011-11-04 13:43 ` Pietro Abate
  0 siblings, 2 replies; 6+ messages in thread
From: Markus Weißmann @ 2011-11-04 13:06 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-11-06 22:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-04 13:06 [Caml-list] elegant subtyping? Markus Weißmann
2011-11-04 13:27 ` Matthias Puech
2011-11-04 13:43 ` Pietro Abate
2011-11-04 14:12   ` Gabriel Scherer
2011-11-04 14:50     ` Vincent Aravantinos
2011-11-06 22:08       ` "Markus W. Weißmann"

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).