Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Re: Empty polymorphic variant type
On Feb 6, 2008 12:16 PM, Till Varoquaux <till.varoquaux@gmail.com> wrote:
> 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

Small addendum:

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

would work but it seems clunky and convoluted.

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



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