Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Empty polymorphic variant type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-02-06 (12:16)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Empty polymorphic variant type
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?