Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jonathan Roewen <jonathan.roewen@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Mixing variant types...
Date: Thu, 12 Jan 2006 14:24:04 +1300	[thread overview]
Message-ID: <ad8cfe7e0601111724t44b6966di5d803949161676ee@mail.gmail.com> (raw)
In-Reply-To: <ad8cfe7e0601110236r6e12fcc0pa30d958ba579c3f@mail.gmail.com>

I've played with coercing to a wider type in the toplevel, and the
following works fine:

# type a = [ `Repaint ];;
type a = [ `Repaint ]
# type b = [ `New_window ];;
type b = [ `New_window ]
# let f () : a = `Repaint;;
val f : unit -> a = <fun>
# let g () : b = `New_window;;
val g : unit -> b = <fun>
# let l = [ (f :> (unit -> [`Repaint|`New_window])); (g :> (unit ->
[`Repaint|`New_window]))];;
val l : (unit -> [ `New_window | `Repaint ]) list = [<fun>; <fun>]
# List.map (fun f -> f ()) l;;
- : [ `New_window | `Repaint ] list = [`Repaint; `New_window]
# let ll = [ ((f ()) :> [`Repaint|`New_window]); ((g ()) :> [a|b]) ];;
val ll : [ `New_window | `Repaint ] list = [`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 = {
	source: 'a;
	chan: ('a * 'b) Event.channel;
}

let send channel value = Event.send channel.chan (channel.source, value)

let receive channel = Event.receive channel.chan

(* Module Window_system *)
type event = [ `Repaint ]
type control = [ `New_window ]
type window = {
	mutable bounds: bounds;
	
	surface: Cairo.image_surface;
	
	mutable clips: bounds list;
	
	control: (window, event) Channel.channel;
}

type ws_event = (window * [event | control]) Event.event

let create left top width height =
  let rec window = {
    ...
    control = { source = window; chan = Event.new_channel (); };
  }

let run () =
  while true do
    let sources =
      ((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 = (window * [ `New_window | `Repaint ]) Event.event;
it has type (window * event) Event.event but is here used with type
  ws_event = (window * [ `New_window | `Repaint ]) Event.event
Type event = [ `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


  reply	other threads:[~2006-01-12  1:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-11 10:36 Jonathan Roewen
2006-01-12  1:24 ` Jonathan Roewen [this message]
2006-01-12  2:45   ` skaller
2006-01-12  3:22   ` Jacques Garrigue
2006-01-12  3:57     ` skaller
2006-01-13  4:57       ` Jacques Garrigue
2006-01-13  7:56         ` skaller
2006-01-13  9:37           ` Jacques Garrigue
2006-01-12  3:59     ` Jonathan Roewen
  -- strict thread matches above, loose matches on Subject: below --
2006-01-11  9:56 Jonathan Roewen

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=ad8cfe7e0601111724t44b6966di5d803949161676ee@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@yquem.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