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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id D3B75BC58 for ; Fri, 17 Sep 2010 10:57:28 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmIEAP7JkkxQW+UMgWdsb2JhbACUMI1jFQEBFiIiwT2FQQSJA4Es X-IronPort-AV: E=Sophos;i="4.56,381,1280700000"; d="scan'208";a="59426917" Received: from lo.gmane.org ([80.91.229.12]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Sep 2010 10:57:28 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OwWl3-00007P-MY for caml-list@inria.fr; Fri, 17 Sep 2010 10:57:25 +0200 Received: from ks368928.kimsufi.com ([94.23.39.26]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Sep 2010 10:57:25 +0200 Received: from sylvain by ks368928.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Sep 2010 10:57:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: Create a constraint between variant type and data list Date: Fri, 17 Sep 2010 08:57:15 +0000 (UTC) Message-ID: References: X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ks368928.kimsufi.com User-Agent: slrn/pre1.0.0-11 (Linux) X-Spam: no; 0.00; le-gall:01 le-gall:01 lgpl:01 lgpl:01 oleg:01 hashtable:01 mli:01 gpl:01 gpl:01 wrote:01 constraint:01 variant:02 variant:02 data:02 data:02 Hello all, On 03-09-2010, Sylvain Le Gall wrote: > Hello all, > > I would like to somehow enforce that a variant type is associated with > an entry in a data list. > > For example, > > I would like to define: > > type license = GPL | LGPL > > and > > let data = [ GPL, "GNU Public license"; > LGPL, "GNU Lesser General Public license" ] > > Thank you for all your answer. I pick the one from oleg@okmij.org, I hide the license with a type and the creation of license is done in the module. The to_string/from_string is done by registering extra data in an Hashtable. See the implementation here. http://darcs.ocamlcore.org/cgi-bin/darcsweb.cgi?r=oasis;a=headblob;f=/src/oasis/OASISLicense.mli http://darcs.ocamlcore.org/cgi-bin/darcsweb.cgi?r=oasis;a=headblob;f=/src/oasis/OASISLicense.ml Regards, Sylvain Le Gall