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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Mixing variant types...
On Thu, 2006-01-12 at 14:24 +1300, Jonathan Roewen wrote:

> So, it all works fine & dandy. So I'm trying to duplicate this with my
> window system problem.

[ .. ]

Try this:


(* 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 ec = [ event | control ]
type window = {
        control: (window, event) channel;
}

type ws_event = (window * ec) Event.event


let run () =
  let internal_control = Event.new_channel ()  in
  while true do
    let sources =
      ((Event.receive internal_control) :> ws_event) ::
      List.map (fun w ->
        Event.wrap (receive w.control) (fun (w,e) -> w, (e:> ec))
      )
      [] (* !windows .. *)
    in
    match Event.select sources with
    | (source, `Repaint) -> () (* repaint source *)
    | _ -> ()
  done

;;


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net