From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA24959; Thu, 17 Jan 2002 00:32:59 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA24983 for ; Thu, 17 Jan 2002 00:32:59 +0100 (MET) Received: from mandelbrot.house (host217-35-46-142.in-addr.btopenworld.com [217.35.46.142]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g0GNWv514622 for ; Thu, 17 Jan 2002 00:32:58 +0100 (MET) Received: by mandelbrot.house (Postfix, from userid 1001) id 300646B; Wed, 16 Jan 2002 23:32:56 +0000 (GMT) Date: Wed, 16 Jan 2002 23:32:55 +0000 From: Ceri Storey To: Warp Cc: OCaml Subject: Re: [Caml-list] Type hidding Message-ID: <20020116233255.GA3044@mandelbrot.house> References: <001601c19ec9$bfe251e0$eb00a8c0@warp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001601c19ec9$bfe251e0$eb00a8c0@warp> User-Agent: Mutt/1.3.25i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Jan 16, 2002 at 09:09:48PM +0100, Warp wrote: > external set_window_data : wnd:hwnd -> 'a -> unit = "set_window_data" > external get_window_data : wnd:hwnd -> 'a = "get_window_data" > > I know that's very type-unsafe and all, but i really need the user to be > able to put any kind of data into it. If you got another idea, please let me > know. Could i suggest that you add a type variable to hwnd to make it type-safe? eg: instead of type hwnd = ... have: type 'a hwnd = ... so the functions would have the types: external set_window_data : wnd:'a hwnd -> 'a -> unit = "set_window_data" external get_window_data : wnd:'a hwnd -> 'a = "get_window_data" If hwnd is a pre-existing type (as i suspect it is) then you could create a type alias that uses phantom types (as far as i understand them, at least), ie: type 'a my_hwnd = hwnd This way you will ensure the same type of data is set / got from the window. > > BTW, then with my handle i'm doing that : > (set_window_data wnd 0); > (print_int (get_window_data wnd)); > > but it raises (about the call the get_window_data ) : > This expression has type wnd:hwnd -> 'a but is here used with type int This is an oddity with the use of compulsary labelled arguments, as introduced in ocaml 3.04. You need to specify the label of the argument passed, ie: set_window_data ~wnd:wnd 0; print_int (get_window_data ~wnd:wnd); Hope this helps.. -- Ceri Storey http://pkl.net/~cez/ vi(1)! postfix(7)! pie(5)! ------------------- 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