caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Keiko Nakata <keiko@kurims.kyoto-u.ac.jp>
To: virgile.prevosto@m4x.org
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] any types in signatures of functor arguments
Date: Tue, 25 Oct 2005 18:49:07 +0900 (JST)	[thread overview]
Message-ID: <20051025.184907.68544007.keiko@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20051025105345.319f8366@aloxe.inria.fr>


From: Virgile Prevosto <virgile.prevosto@m4x.org>

> It might be possible to only modify the arguments you give to F, with
> the use of include:
> 
> module M = struct let f (`A x) = x end
> 
> module F(X:sig type s type t = [ `A of s] val f: t -> int end) =
>   struct let f = function `A _ as a -> X.f a | `B -> 0
>   end;;
> 
> module FM = F(struct include M type s = int type t = [ `A of s ])

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.



Regard,
Keiko NAKATA







  reply	other threads:[~2005-10-25  9:49 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 [this message]
2005-10-25 10:08         ` fva en UMBRIEL
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=20051025.184907.68544007.keiko@kurims.kyoto-u.ac.jp \
    --to=keiko@kurims.kyoto-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=virgile.prevosto@m4x.org \
    /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).