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 0B08BBC57 for ; Fri, 3 Sep 2010 19:39:13 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoEBAJLPgEzRVdg2kGdsb2JhbACgfwgVAQEBAQkJDAcRAx+kQYkzghWGTC6IMgEBAwWFNgSKGYhk X-IronPort-AV: E=Sophos;i="4.56,314,1280700000"; d="scan'208";a="58524967" Received: from mail-qw0-f54.google.com ([209.85.216.54]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 Sep 2010 19:39:12 +0200 Received: by qwg5 with SMTP id 5so2513178qwg.27 for ; Fri, 03 Sep 2010 10:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=5L106HoNrf6HmoV14zmRYiyieucT+ucRuhXtfYPkPwI=; b=cwcN7sc5fRREVsw1nNmL7BsYv6KL7A/Q/orK4fymRKxFifbDO1cD+UQRq9Qeh0R9lA fqkA8KidRi2Tw15kNdlp6eCzEKIHbp4H3PNGteG3AlpMEYCsg+QV66vHHfl0rcdenJXQ Tg0oJLXanmWalOPeF3XR8PEIsqGUzOuHFpSeE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=B7MHhFYUvde9TUHCemAZgZuFEYD4jzy6LKse7sfAu/toLslRb8A2alcCFfJCrXk1Ph sl3g4fDCImq8Nwa7r9ir3K/tXwvACO3NQd4OhMNCm99E9pykx4Tn2yMQq/JhbtBHDKDE OuNpCbIpr6PGOweQUAhpH9Gjkew5QENM8gyZU= Received: by 10.229.182.205 with SMTP id cd13mr1012192qcb.30.1283535547606; Fri, 03 Sep 2010 10:39:07 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.28.209 with HTTP; Fri, 3 Sep 2010 10:38:47 -0700 (PDT) In-Reply-To: References: From: bluestorm Date: Fri, 3 Sep 2010 19:38:47 +0200 X-Google-Sender-Auth: E3lUYSYucS4T1lrpSgxZtALFXrk Message-ID: Subject: Re: [Caml-list] Create a constraint between variant type and data list To: Sylvain Le Gall Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; lgpl:01 lgpl:01 compiler:01 compiler:01 ocamlc:01 datatype:01 constructors:01 datatype:01 camlp:01 markus:01 mottl's:01 ocaml:01 ocaml:01 gpl:01 gpl:01 Hi, I do not have a direct solution to your problem. If you want to associate a data with each case, you can use a pattern matching, wich will do the exhaustiveness check : let to_string : license -> _ = function | `GPL -> "GPL" | `LGPL -> "LGPL" You will be warned if you add (or remove) some licenses and forget to change the function. You may, however, want to have a list of all licenses values, instead of a case-handling on each value. I don't know how you could have the compiler check completeness for you, but if you really want that check, there is an extra-linguistic method : declare your value without giving it a type annotation, so that the compiler will infer the covered case, then use a script outside the program, calling "ocamlc -i" to check the inferred signature, and comparing it to you datatype declaration. Finally, I have a third solution based on code generation : given my first solution (turning the association list into a function), what you need is only a list of all the constructors (and you can build your assoc list with List.map (fun x -> x, assoc_function x)). This can easily be generated from the datatype declaration using direct camlp4, or Markus Mottl's type-conv ( http://www.ocaml.info/home/ocaml_sources.html#toc11 ).