Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Matthias Puech <puech@cs.unibo.it>
To: caml-list@inria.fr
Subject: Re: [Caml-list] elegant subtyping?
Date: Fri, 04 Nov 2011 14:27:36 +0100	[thread overview]
Message-ID: <4EB3E848.2010508@cs.unibo.it> (raw)
In-Reply-To: <64822.143.164.102.13.1320411983.squirrel@webmail.mwn.de>

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
>


  reply	other threads:[~2011-11-04 13:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-04 13:06 Markus Weißmann
2011-11-04 13:27 ` Matthias Puech [this message]
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"

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4EB3E848.2010508@cs.unibo.it \
    --to=puech@cs.unibo.it \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox