Browse thread
Empty polymorphic variant type
- Till Varoquaux
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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? Till -- http://till-varoquaux.blogspot.com/