Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Polymorphic variant abbreviations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Patrick M Doane <patrick@w...>
Subject: Re: [Caml-list] Polymorphic variant abbreviations
The last 2 questions were about possible minor improvements with using
abbreviations. Now I'm stumped - can anyone bail me out?

(* Some type definitions and abbreviations *)
type t = ([ `A of 'a list | `B | `C ]) as 'a 
type b = [ `B ]
type c = [ `C ]

(* A rename for one of the abbreviations *)
type b2 = b

(* Use of abbreviation and rename work okay *)
let f1 (#b as x1) (#b as x2) = `A [x1;x2]
let f2 (#b2 as x1) (#b2 as x2) = `A [x1;x2] 

(* Only direct abbreviation works with list constructor *)
let g1 ~(xs : #b list) =
  `A xs

(*
   this doesn't compile - says unbound class b2

let g2 ~(xs : #b2 list) =
  `A xs
*)

(* The first works as I would expect, the second gives a very unexpected
type. There seems to be some kind of unexpected unification going on
between terms. *)

let h1 (#b as x1) (#c as x2) = `A [x1; x2]
let h2 (x1 : #b) (x2 : #c) = `A [x1; x2]


Any ideas?

Thanks,
Patrick


-------------------
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