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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 6F699BBAF for ; Mon, 11 Oct 2010 10:50:03 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An8EAFtsskxQW+UMgWdsb2JhbACUD418FQEBFiIivjCFSASKQQ X-IronPort-AV: E=Sophos;i="4.57,312,1283724000"; d="scan'208";a="73124355" Received: from lo.gmane.org ([80.91.229.12]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Oct 2010 10:50:03 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1P5E52-0000nP-5l for caml-list@inria.fr; Mon, 11 Oct 2010 10:50:00 +0200 Received: from avelizy-155-1-1-48.w83-199.abo.wanadoo.fr ([83.199.40.48]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 11 Oct 2010 10:50:00 +0200 Received: from sylvain by avelizy-155-1-1-48.w83-199.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 11 Oct 2010 10:50:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: Type constraint to explain that a polymorphic variants is included into another Date: Mon, 11 Oct 2010 08:49:51 +0000 (UTC) Message-ID: References: X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: avelizy-155-1-1-48.w83-199.abo.wanadoo.fr User-Agent: slrn/pre1.0.0-18 (Linux) X-Spam: no; 0.00; le-gall:01 variants:01 subset:01 subtyping:01 ocaml:01 typable:01 prerr:01 endline:01 prerr:01 endline:01 ocamlc:01 intersection:01 polymorphic:01 wrote:01 wrote:01 Hello, On 08-10-2010, Jacques Garrigue wrote: > On 2010/10/09, at 2:13, Sylvain Le Gall wrote: > >> Hello all, >> >> I would like to build an interface for plugins that allow to extract at the >> same time a very specific data for a plugin family and to extract >> general help for plugins. >> >> Here is an example: > > [...] > >> This code doesn't compile because I see no way to explain that F.kind is >> included into plugin_kind. > > I'm not sure of what you are trying to do, but private rows where introduced > with this goal in mind. > > The idea is to change the abstract definition of kind in PLUGIN_FAMILY to > > type kind = private [< plugin_kind] > > meaning that kind can be instantiated to any subset of plugin_kind. > You can then use subtyping to convert from kind to plugin_kind. > Very nice OCaml extension. It indeed solves my problem. I was aware of private type, but don't yet know how to use it. > Here is a typable version of your code. > > let run pkg = > prerr_endline (help (pkg.plugin_build :> MapPlugin.key)); > prerr_endline (help (pkg.plugin_install :> MapPlugin.key)); > (Build.act pkg.plugin_build) (); > Install.act pkg.plugin_install [] > That is perfect. If I add the following call, with your solution: (Install.act pkg.plugin_build) [] I get this error: ocamlc -o test test.ml File "test.ml", line 84, characters 14-30: Error: This expression has type [ `Build ] plugin = [ `Build ] * string but an expression was expected of type [ `Install ] plugin = [ `Install ] * string These two variant types have no intersection make: *** [all] Erreur 2 This is exactly what I want. Thanks, Sylvain Le Gall