From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 23385BB81 for ; Thu, 12 Jan 2006 02:24:06 +0100 (CET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.204]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k0C1O5wk009104 for ; Thu, 12 Jan 2006 02:24:05 +0100 Received: by wproxy.gmail.com with SMTP id i23so300236wra for ; Wed, 11 Jan 2006 17:24:05 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=pNUMEQ2Nne70d4b24oMgG1QUu5VSw7Zibve7wYSFoTiYr4M/wcrwNdLNQajjjBvGSMdr8180d5WBb0JgQobD8tmjoChc3N1utfJ3Hs1ESlxGH4Sz31XGCqOqlQrKMomz4sDqXMTP5mLFTW7bjSQ9NwEQHaMGZou4UKuoU4Rv6s0= Received: by 10.65.205.8 with SMTP id h8mr517344qbq; Wed, 11 Jan 2006 17:24:04 -0800 (PST) Received: by 10.65.22.19 with HTTP; Wed, 11 Jan 2006 17:24:04 -0800 (PST) Message-ID: Date: Thu, 12 Jan 2006 14:24:04 +1300 From: Jonathan Roewen Subject: Re: [Caml-list] Mixing variant types... Cc: caml-list@yquem.inria.fr In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: X-Miltered: at nez-perce with ID 43C5AFB5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 toplevel:01 val:01 val:01 mutable:01 mutable:01 rec:01 coerced:01 toplevel:01 height:98 expression:01 variant:02 variant:02 width:97 match:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 I've played with coercing to a wider type in the toplevel, and the following works fine: # type a =3D [ `Repaint ];; type a =3D [ `Repaint ] # type b =3D [ `New_window ];; type b =3D [ `New_window ] # let f () : a =3D `Repaint;; val f : unit -> a =3D # let g () : b =3D `New_window;; val g : unit -> b =3D # let l =3D [ (f :> (unit -> [`Repaint|`New_window])); (g :> (unit -> [`Repaint|`New_window]))];; val l : (unit -> [ `New_window | `Repaint ]) list =3D [; ] # List.map (fun f -> f ()) l;; - : [ `New_window | `Repaint ] list =3D [`Repaint; `New_window] # let ll =3D [ ((f ()) :> [`Repaint|`New_window]); ((g ()) :> [a|b]) ];; val ll : [ `New_window | `Repaint ] list =3D [`Repaint; `New_window] So, it all works fine & dandy. So I'm trying to duplicate this with my window system problem. I have: (* Module Channel *) type ('a,'b) channel =3D { =09source: 'a; =09chan: ('a * 'b) Event.channel; } let send channel value =3D Event.send channel.chan (channel.source, value) let receive channel =3D Event.receive channel.chan (* Module Window_system *) type event =3D [ `Repaint ] type control =3D [ `New_window ] type window =3D { =09mutable bounds: bounds; =09 =09surface: Cairo.image_surface; =09 =09mutable clips: bounds list; =09 =09control: (window, event) Channel.channel; } type ws_event =3D (window * [event | control]) Event.event let create left top width height =3D let rec window =3D { ... control =3D { source =3D window; chan =3D Event.new_channel (); }; } let run () =3D while true do let sources =3D ((Event.receive internal_control) :> ws_event) :: List.map (fun w -> ((Channel.receive w.control) :> ws_event)) !windows in (* Line 99 *) match Event.select sources with | source, `Repaint -> repaint source | _ -> () done And I get the following error: File "window_system.ml", line 99, characters 23-50: This expression cannot be coerced to type ws_event =3D (window * [ `New_window | `Repaint ]) Event.event; it has type (window * event) Event.event but is here used with type ws_event =3D (window * [ `New_window | `Repaint ]) Event.event Type event =3D [ `Repaint ] is not compatible with type [ `New_window | `Repaint ] The first variant type does not allow tag(s) `New_window The toplevel has just proven to me that this can be done, so I don't understand what's going on here. Kindest Regards, Jonathan Roewen