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 OAA01630; Fri, 14 Sep 2001 14:53:43 +0200 (MET DST) 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 OAA02113 for ; Fri, 14 Sep 2001 14:53:42 +0200 (MET DST) Received: from tet.kurims.kyoto-u.ac.jp ([61.127.175.250]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f8ECref00378 for ; Fri, 14 Sep 2001 14:53:40 +0200 (MET DST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.11.3/8.11.3) with ESMTP id f8E8nMc35156; Fri, 14 Sep 2001 17:49:23 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: jhw@wetware.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Re: Phantom types (very long) In-Reply-To: <25775F60-A6E4-11D5-9E93-000502DB38F5@mac.com> References: <20010910154559.O6031-100000@shell5.ba.best.com> <25775F60-A6E4-11D5-9E93-000502DB38F5@mac.com> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010914174922Y.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 14 Sep 2001 17:49:22 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > This "phantom types" design pattern is one I have never seen before. It > doesn't seem to be used in the standard library anywhere I can see. It > looks like it might be useful in presenting a safer network programming > interface than the low-level wrappers around BSD sockets (which I've > never liked). Thay are used in both Bigarray and Labltk (the 'a widget type). In fact they were already used in Labltk before the word phantom started to be used for them. > Are there any other mind-blowingly elegant design patterns lurking in > the corners of the Caml type inference engine that I should know about? I don't know if this is mind blowing, but thanks to variance annotations on abstract types, you can also have subtyping on "phantom" types. This is used in lablgtk for instance: type (-'a) gtkobj type widget = [`widget] type container = [`widget|`container] type box = [`widget|`container|`box] now you can cast safely between classes: (mybox : box gtkobj :> container gtkobj) Note that the parameter must be contravariant if you use polymorphic variant types as indexes, or covariant if you rather use object types. This also works ok with polymorphism, encoding inheritance (even multiple) in a direct way. val add : [> `container] gtkobj -> [> `widget] gtkobj -> unit Cheers, Jacques Garrigue ------------------- 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