From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D4FEABB81 for ; Thu, 10 Nov 2005 04:50:04 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAA3o4CC008081 for ; Thu, 10 Nov 2005 04:50:04 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA05546 for ; Thu, 10 Nov 2005 04:50:03 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAA3o1O7013419 for ; Thu, 10 Nov 2005 04:50:03 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id jAA3o0Aw022756 for ; Thu, 10 Nov 2005 12:50:00 +0900 (JST) Date: Thu, 10 Nov 2005 12:50:00 +0900 (JST) Message-Id: <20051110.125000.68545682.keiko@kurims.kyoto-u.ac.jp> To: caml-list@inria.fr Subject: private rows question From: Keiko Nakata X-Mailer: Mew version 4.2 on Emacs 20.7 / Mule 4.1 (AOI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4372C36C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4372C369.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; functor:01 typable:01 sig:01 val:01 struct:01 reuse:01 verbose:01 sig:01 val:01 struct:01 rec:01 reuse:01 rec:01 fab:98 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello. Why the following functor G is not typable? I thought that g could have a type something like int -> [< `A | `B ]. module G(X:sig type t = private [< `A ] val f : int -> t end) = struct let g x = if x = 0 then `B else X.f x end This question comes from a wish to reuse my program codes using private rows in the following way: (In my actual program, each branches of the function g of F performs much more verbose task. Thus, writing duplicate codes is a bit painful.) module F(X:sig type t = private [< `A | `B | `C] val f : [`III of string] -> t end) = struct let rec g binds = function [] -> [] | `Var name :: tl -> (List.assoc name binds) :: (g binds tl) | (`I name) :: tl -> `A :: (g ((name, `A) :: binds) tl) | (`II name) :: tl -> `B :: (g ((name, `B) :: binds ) tl) | (`III _ as iii) :: tl -> let iii' = X.f iii in iii' :: (g ((name, iii') :: binds) tl) end module ABC = struct type t = [`A | `B | `C] let f = function `III name -> `C end module AB = struct type t = [`A | `B] let f = function `III name -> `A end module FABC = F(ABC) module FAB = F(AB) let abc : [`I | `II | `III] list -> [`A | `B | `C] list = FABC.g let ab : [`I | `II | `III] list -> [`A | `B ] list = FBC.g I thought that the reuse might be possible by making the function g take the function f as an argument, as in follows: let rec g f binds = function [] -> [] | `Var name :: tl -> (List.assoc name binds) :: (g f binds tl) | (`I name) :: tl -> `A :: (g f ((name, `A) :: binds) tl) | (`II name) :: tl -> `B :: (g f ((name, `B) :: binds ) tl) | (`III name as iii) :: tl -> let iii' = f iii in iii' :: (g f ((name, iii') :: binds) tl) let f = function `III name -> `C let abc binds ls : [ `A | `B | `C] = g f binds ls However, this attempt also failed... (Anyway, I do not find the addition of f to g's arguments pleasant, since this could increase the number of g's formal parameters unnecessarily when I define more complicated functions.) Best regards, Keiko NAKATA