Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] const equivalent for mutable types?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@j...>
Subject: Re: [Caml-list] Phantom types
On Monday 23 August 2004 10:49, Jon Harrop wrote:
> Secondly, specifying the types as Markus did (e.g. [> `Even])...

I should add, using:

  val add_even_even : [> `Even ] t -> [> `Even ] t -> [> `Even ] t
  val add_even_odd : [> `Even ] t -> [> `Odd ] t -> [> `Odd ] t

allows:

# PhantomInt.add_even_odd i j;;
val k : _[> `Odd ] PhantomInt.t = <abstr>

which can then be misused:

# PhantomInt.add_even_even i k;;
- : [ `Even ] PhantomInt.t = <abstr>

I think this is because [> `Even] means any superset of [ `Even ] whereas [< 
`Even], which was probably intended, means any subset of [ `Even ]. Indeed, 
the latter appears to work.

Cheers,
Jon.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners