Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: David Chemouil <david.chemouil@irit.fr>
To: Liste Caml <caml-list@inria.fr>
Subject: [Caml-list] phantom types and coercions
Date: Wed, 03 Oct 2001 11:21:10 +0200	[thread overview]
Message-ID: <3BBAD886.3CCB5AC4@irit.fr> (raw)


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


             reply	other threads:[~2001-10-03  9:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-03  9:21 David Chemouil [this message]
2001-10-03 14:17 ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BBAD886.3CCB5AC4@irit.fr \
    --to=david.chemouil@irit.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox