caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
To: David Teller <David.Teller@univ-orleans.fr>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Labelling trees
Date: Wed, 06 Jun 2007 23:22:56 +0200	[thread overview]
Message-ID: <466725B0.2010308@univ-savoie.fr> (raw)
In-Reply-To: <1181158983.9266.12.camel@Blefuscu>

David Teller a écrit :
>    Hi everyone,
>  I'm currently in the very first stages of writing down a prototype
> implementation of a type checker. At the moment, I'm looking for "the
> nicest" way of labelling my abstract syntax tree with type annotations
> -- without corrupting the AST at all, if possible.
>
>
> Say I have
>
> type my_expression = ESomeConstructor  of ...
>                    | ESomeConstructor2 of ...
>                    | ESomeConstructor3 of my_function
> and  my_function   = FSomeConstructor ...
>
>
> A first idea would be to replace this structures with
>
> type 'a my_expression = ESomeConstructor  of ...
>                       | ESomeConstructor2 of ...
>                       | ESomeConstructor3 of 'a my_function
> and  'a my_function   = FSomeConstructor ...
>
> That would let me annotate instances of my_expression or my_function
> with informations of type 'a. However, this won't scale in case I decide
> that my static checker will need annotations of different types for
> my_expression and my_function. Of course, my AST is actually a tad more
> complex and would require about 15 type arguments, which I don't
> consider very nice. 
>
> Intuitively, using functors will yield the same kind of half-satisfying
> results.
>
> Any suggestions ?
>
>   
I can't ressit ... use pml 
(http://www.lama.univ-savoie.fr/~raffalli/repos/pml) in one week from 
now (I am currently implementing what you need,
this is why I am answering).

You will be able to write things like :

type AST =
  Nope[]
| App[AST,AST]

val rec decorate_with_size  ast =
  Nope[] -> 
    { Nope[] with val size = 0 } (* Here I am lying pml does not support 
native int yet, nor it will in one week *)
| App[u,v] ->
    let u' = decorate_with_size u and v' = decorate_with_size v in
    { App[decorate u, decorate v] with val size = 1 + u'.size  +  v'.size }

Moreover, the result type of decorate_with_size (which is {AST with val 
size : int }) is a subtype of AST
and this subtyping is completely implicit (no typecast needed) ...

OK, pml does not have native int (it has multiprecision nat) and no IO 
yet, it is interpreted (but not that slow),
probably buggy ... But you will soon be able to specify and prove your 
code too ...

Cheers,
Christophe



  reply	other threads:[~2007-06-06 21:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-06 19:43 David Teller
2007-06-06 21:22 ` Christophe Raffalli [this message]
2007-06-07  1:00 ` [Caml-list] " skaller
2007-06-07 14:26   ` Till Varoquaux
2007-06-07 23:09     ` skaller
2007-06-08  9:52       ` Till Varoquaux
2007-06-08 10:32         ` skaller
2007-06-07 14:25 ` Christian Stork
2007-06-07 23:48 ` Jeremy Yallop

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=466725B0.2010308@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=David.Teller@univ-orleans.fr \
    --cc=caml-list@yquem.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;
as well as URLs for NNTP newsgroup(s).