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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DF326BB83 for ; Sat, 19 Aug 2006 17:14:55 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7JFEG6g025022 for ; Sat, 19 Aug 2006 17:14:55 +0200 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 QAA20539 for ; Sat, 19 Aug 2006 16:51:54 +0200 (MET DST) 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.6/8.13.6) with ESMTP id k7JEprH5022738 for ; Sat, 19 Aug 2006 16:51:54 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id k7JEpbp8018330; Sat, 19 Aug 2006 23:51:37 +0900 (JST) Date: Sat, 19 Aug 2006 23:51:34 +0900 (JST) Message-Id: <20060819.235134.94072006.garrigue@math.nagoya-u.ac.jp> To: carette@mcmaster.ca Cc: caml-list@inria.fr Subject: Re: [Caml-list] How do I abstract out polymorphic variants via functors? From: Jacques Garrigue In-Reply-To: <44E5C226.3030802@mcmaster.ca> References: <44E5C226.3030802@mcmaster.ca> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; variants:01 functors:01 variants:01 functors:01 sig:01 sig:01 abstraction:01 structurally:01 variance:01 annotations:01 subtyping:01 polymorphism:01 2006:98 polymorphic:01 polymorphic:01 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 From: Jacques Carette Subject: [Caml-list] How do I abstract out polymorphic variants via functors? Date: Fri, 18 Aug 2006 09:35:34 -0400 > I have 3 module types, each of which start out "the same", viz: > module type DETERMINANT = sig > type 'a lstate > type 'a tag_lstate = [`TDet of 'a lstate ] > type ('b,'v) lm = ('a,'v,'s,'w) cmonad > constraint 's = [> 'a tag_lstate] > constraint 'b = 'a * 's * 'w > ... > end > module type RANK = sig > type 'a lstate = ('a, int ref) code > type 'a tag_lstate = [`TRan of 'a lstate ] > type ('b,'v) lm = ('a,'v,'s,'w) cmonad > constraint 's = [> 'a tag_lstate] > constraint 'b = 'a * 's * 'w > ... > end [...] > The only thing different between those 3 is the name of the polymorphic > variant - so clearly an opportunity for abstraction! But I can't seem > to achieve this. Is there a way? Not currently. The problem is that [> 'a tag_lstate] is only defined when tag_lstate has a concrete definition. So if you abstract tag_lstate, you cannot keep this constraint. Private row types won't help either, since they can only be implemented by structurally monomorphic types. So I see no way out, at least with this encoding. Another approach might be to add variance annotations, and use subtyping rather than polymorphism (but I don't know whether it makes sense here.) Jacques Garrigue