From: bluestorm <bluestorm.dylc@gmail.com>
To: Sylvain Le Gall <sylvain@le-gall.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Create a constraint between variant type and data list
Date: Fri, 3 Sep 2010 19:38:47 +0200 [thread overview]
Message-ID: <AANLkTimqCdKkDrmyuoVH3Q2YJ_uGohQSs-6UcCDkebx0@mail.gmail.com> (raw)
In-Reply-To: <slrni82bc0.skq.sylvain@gallu.homelinux.org>
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 ).
next prev parent reply other threads:[~2010-09-03 17:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-03 17:16 Sylvain Le Gall
2010-09-03 17:38 ` bluestorm [this message]
2010-09-03 21:28 ` Sylvain Le Gall
2010-09-17 7:29 ` [Caml-list] " Maxence Guesdon
2010-09-03 18:51 ` [Caml-list] " Martin Jambon
2010-09-03 19:39 ` Ashish Agarwal
2010-09-03 21:13 ` Maxence Guesdon
2010-09-03 21:25 ` Sylvain Le Gall
2010-09-04 6:35 ` [Caml-list] " Julien Signoles
2010-09-04 6:40 ` Julien Signoles
2010-09-04 16:25 ` Anil Madhavapeddy
2010-09-17 8:57 ` Sylvain Le Gall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimqCdKkDrmyuoVH3Q2YJ_uGohQSs-6UcCDkebx0@mail.gmail.com \
--to=bluestorm.dylc@gmail.com \
--cc=caml-list@inria.fr \
--cc=sylvain@le-gall.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox