caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Empty polymorphic variant type
@ 2008-02-06 12:16 Till Varoquaux
  2008-02-06 12:24 ` Till Varoquaux
  0 siblings, 1 reply; 5+ messages in thread
From: Till Varoquaux @ 2008-02-06 12:16 UTC (permalink / raw)
  To: caml-list List

Polymorohic variants are great to encode permissions as phantom types.
This usage is hindered by the apparent impossibility to declare the
empty polymorphic type.

To illustrate this use case I'll take a bogus example: suppose one is
handling accounts, you might want to be able to add a permission on
private information (NIN, passwords etc..). So you could be handling
accounts where you'd have read permission, write permission both or
none. By using a polymorphic variant type:

type 'a account constraint 'a = [< `Read | `Write ];;

to could express as closed type 3 of 4 possible case, the one where
you have neither read nor write access cannot be expressed.

One could use objects as phantom types:

type 'a account constraint 'a = <..>;;

but this solution is just not as elegant. Any other ideas?

Till
-- 
http://till-varoquaux.blogspot.com/


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-02-07 15:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-06 12:16 Empty polymorphic variant type Till Varoquaux
2008-02-06 12:24 ` Till Varoquaux
2008-02-06 12:33   ` [Caml-list] " Bünzli Daniel
2008-02-06 13:13     ` Till Varoquaux
2008-02-07 15:18   ` Christophe TROESTLER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).