[
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: | David Chemouil <david.chemouil@i...> |
| Subject: | [Caml-list] phantom types and coercions |
Hello, we have noticed a strange (at least to us) behavior of the coercion operator over phantom types. Here is an example: # type n = [`Pos];; (* non-negative number *) type n = [ `Pos] # type z = [`Neg | `Pos];; (* integer *) type z = [ `Neg | `Pos] # type (+'ph) expr = Expr of int;; (* phantom type *) type 'a expr = Expr of int # let x = ((Expr 1) : n expr);; val x : n expr = Expr 1 # (x:> z expr);; (* okay *) - : z expr = Expr 1 # let y = ((Expr 1) : z expr);; val y : z expr = Expr 1 # (y :> n expr);; (* ??? *) - : n expr = Expr 1 So, we observe the same behavior whatever the variance specification is. # type 'ph expr = Expr of int;; (* without variance *) type 'a expr = Expr of int # let x = ((Expr 1) : n expr);; val x : n expr = Expr 1 # (x:> z expr);; (* ??? *) - : z expr = Expr 1 # let y = ((Expr 1) : z expr);; val y : z expr = Expr 1 # (y :> n expr);; (* ??? *) - : n expr = Expr 1 # type (-'ph) expr = Expr of int;; (* contravariance *) type 'a expr = Expr of int # let x = ((Expr 1) : n expr);; val x : n expr = Expr 1 # (x:> z expr);; - : z expr = Expr 1 # let y = ((Expr 1) : z expr);; val y : z expr = Expr 1 # (y :> n expr);; - : n expr = Expr 1 We wonder whether it is a bug or not (anyway, this is rather counter-intuitive)...? dc -- David Chemouil [mailto:david.chemouil@irit.fr] -- -- Zeno group [http://www.irit.fr/zeno] -- Institut de recherche en informatique de Toulouse ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr