Version française
Home     About     Download     Resources     Contact us    
Browse thread
Create a constraint between variant type and data list
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Maxence Guesdon <maxence.guesdon@i...>
Subject: Re: [Caml-list] Create a constraint between variant type and data list
Le Fri, 3 Sep 2010 17:16:48 +0000 (UTC),
Sylvain Le Gall <sylvain@le-gall.net> a écrit :

> 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" ]
> 
> 
> I would like to enforce that all variants of license are in the
> association list.
> 
> I have tried to use polymorphic variants, but don't see how to enforce
> this constraint.
> 
> The point, is that if I add a new variant to license (e.g. BSD3), the
> compiler output an error because this new variant is not in data list.
> 
> Any ideas ? If you need to use another type expression rather than
> variant, please do so, as long as I am able to link the license type
> and data list.

A solution is to add your new license to your list of associations, then
the compiler will complain about the unknown variant :)

Regards,

-- 
Maxence Guesdon