Version française
Home     About     Download     Resources     Contact us    
Browse thread
any types in signatures of functor arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: fva en UMBRIEL <fva@t...>
Subject: Re: [Caml-list] any types in signatures of functor arguments
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.
>  
>