Version française
Home     About     Download     Resources     Contact us    
Browse thread
Attach an invariant to a type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stéphane_Lescuyer <lescuyer@l...>
Subject: Re: [Caml-list] Attach an invariant to a type
On Jan 31, 2008 8:13 PM, Hezekiah M. Carty <hcarty@atmos.umd.edu> wrote:
>
> This code does not work for me.  I get a "This fixed type is not an
> object or variant" error on the "type t = private int" line.  From the
> manual it looks like you would have to use something like this:
>
> type t = private Index of int
>
> to take advantage of private types.  Am I missing something?
>

No you're not :) as far as I know, a private type can only be a record
or a variant.
It prevents one from constructing values of this type, but still
allows pattern-matching
on these values.

I guess that making types like "int" private would require the system
(among other things) to decide whether you're using a given integer as
a Subindex.t or not. At first glance, it seems it is a harder problem
than just forbidding the construction of any value of a given type.
Just my 0.02€ :-)

Stéphane L.