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: Romain Bardou <Romain.Bardou@l...>
Subject: Re: [Caml-list] Attach an invariant to a type
Wow, how could I forget about private types.

However, you still need the of_int function.

module Subindex: sig
   type t = private int
   val make: int -> t
end = struct
   type t = int
   let make n =
     assert (n >= 10 && x <= 100);
     n
end

	Romain Bardou

David Teller a écrit :
> Actually, OCaml contains something slighly simpler than this of_int /
> to_int mechanism: private types.
> 
> 
> On Thu, 2008-01-31 at 14:50 +0100, Romain Bardou wrote:
> 
>> 2) (much better imo) use a module with an abstract type, such as:
>