caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* polymorphic variant and subtyping
@ 2000-12-07 20:01 Remi VANICAT
  0 siblings, 0 replies; only message in thread
From: Remi VANICAT @ 2000-12-07 20:01 UTC (permalink / raw)
  To: caml-list

I have try this :

# type 'a t = [ `A of 'a];;
type 'a t = [ `A of 'a]
# type arg1 = [`A | `B];;
type arg1 = [ `A | `B]
# type arg2 = [`A];;
 type arg2 = [ `A]
# type t1 = arg1 t;;
type t1 = arg1 t
# type t2 = arg2 t;;
type t2 = arg2 t
# let a2 = (`A : arg2);;
val a2 : arg2 = `A
# let a1 = (a1 :> arg1);;
val a1 : arg1 = `A
# let t2 = (`A a2 : t2);;
val t2 : t2 = `A `A
# let t1 = (t2 :> t1);;
This expression cannot be coerced to type t1 = [ `A of arg1]; it has type
  t2 = [ `A of arg2]
but is here used with type arg1 #t as 'a = 'a
Type arg2 = [ `A] is not compatible with type arg1 = [ `A | `B] 

but 
# let f : t2 -> t1 = function
    `A x -> `A (x :> arg1)

do what i want. It seems to me that caml don't infere subtyping
relationship, when ithe subtyping relation come from argument of the
type. 

Is there a good way in ocaml of doing this ? 


-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-12-08  9:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-07 20:01 polymorphic variant and subtyping Remi VANICAT

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).