caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: fva en UMBRIEL <fva@tsc.uc3m.es>
To: Keiko Nakata <keiko@kurims.kyoto-u.ac.jp>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] any types in signatures of functor arguments
Date: Tue, 25 Oct 2005 12:08:45 +0200	[thread overview]
Message-ID: <435E042D.1060709@tsc.uc3m.es> (raw)
In-Reply-To: <20051025.184907.68544007.keiko@kurims.kyoto-u.ac.jp>

Hi,

given your problem I wonder whether the use of modules, if elegant, is 
not overkill. I recall an extensible solution to such syntactic trees 
written with polymorphic variants in one of the papers/tutorials by 
Jacques Garrigue. Perhaps you could have a look at those for inspiration.

Regards

    F. Valverde

Keiko Nakata wrote:

>Thanks for the reply.
>
>I should describe my program in more detail.
>What I want to do would be summarized in the following program.
>(Suppose that modules Int, String, and Subst are in separate files,
>and have many more type definitions and functions actually.)
>
>module Int = struct
>  type mexp = [`Str of item list | `Var of string]
>  and item = [`Mod of mexp | `Term of int]
>  type env = (string * mexp) list
>  let subst env name = List.assoc name env
>end
>
>module String = struct
>  type mexp = [`Str of item list | `Var of string]
>  and item = [`Mod of mexp | `Term of string]
>  type env = (string * mexp) list
>  let subst env name = List.assoc name env
>end
>
>module Subst (X: sig 
>  type mexp = [`Str of item list | `Var of string]
>  and item = [`Mod of mexp | `Term of _ ]
>  type env = (string * mexp) list
>  val subst : env -> string -> mexp end) = struct 
>    let rec subst_mexp env = function
>	`Str items -> `Str (List.map (subst_item env) items)
>      | `Var name -> X.subst env name
>    and subst_item env = function
>	`Mod mexp -> `Mod (subst_mexp env mexp)
>      | `Term t -> `Term t
>  end
>    
>
>One may say that I should fist define the type item0 as
>
>type ('a,'b) item0 = [`Mod of 'a | `Term of 'b ]
>
>then define type mexp and item as
>
>type mexp = [`Str of item list | `Var of string]
>and item = (mexp, int) item0 
>
>This will work.
>However, I cannot decide where to put the definition of item0 
>when Int and String are in separate files.
>Additionally, while it will not a big problem,
>this encoding will make my program more verbose.
>  
>


  reply	other threads:[~2005-10-25 10:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-24  8:51 Keiko Nakata
2005-10-24 14:08 ` [Caml-list] " Brian Hurt
2005-10-25  2:22   ` Keiko Nakata
2005-10-25  8:53     ` Virgile Prevosto
2005-10-25  9:49       ` Keiko Nakata
2005-10-25 10:08         ` fva en UMBRIEL [this message]
2005-10-25 12:15 ` Hendrik Tews

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=435E042D.1060709@tsc.uc3m.es \
    --to=fva@tsc.uc3m.es \
    --cc=caml-list@yquem.inria.fr \
    --cc=keiko@kurims.kyoto-u.ac.jp \
    /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).