From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 35142BDCB for ; Mon, 5 Sep 2005 01:28:57 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j84NSutq021572 for ; Mon, 5 Sep 2005 01:28:56 +0200 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 BAA12828 for ; Mon, 5 Sep 2005 01:28:55 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j84NSrXa011220 for ; Mon, 5 Sep 2005 01:28:55 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j84NSnnw016768; Mon, 5 Sep 2005 08:28:49 +0900 (JST) Date: Mon, 05 Sep 2005 08:28:39 +0900 (JST) Message-Id: <20050905.082839.104027887.garrigue@math.nagoya-u.ac.jp> To: lukstafi@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Existential types From: Jacques Garrigue In-Reply-To: <4a708d205090412435bca9cb0@mail.gmail.com> References: <4a708d205090412435bca9cb0@mail.gmail.com> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 431B8338.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 431B8335.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 existential:01 lukasz:01 one-way:01 existential:01 labltk:01 encodes:01 distinctions:01 ocaml:01 ocaml:01 one-way:01 subtyping:01 abstract:01 unsafe:01 jacques:01 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=none autolearn=disabled version=3.0.3 From: Lukasz Stafiniak > I use an abstract type and a one-way typecast operator to implement > existential quantification; e. g. > > type 'a t > type unknown_t > let some (v : 'a t) = ((Obj.magic v) : unknown_t t) > > Good? This is a standard technique that is used in labltk for instance. There should be no problem as long as your ['a t] type has a uniform representation (i.e. this use of magic only encodes more refined type distinctions.) Note that if your values are implemented in ocaml, there is a reasonable possibility that you could avoid the magic altogether. And if this is not the case (i.e. implemented in ocaml but magic required), there is a serious risk that this is actually unsound. Remember that the function Obj.repr of type ['a -> Obj.t] is unsound, contrary to the intuition. Which leads to the rule of thumb: the only "safe" uses of magic are when dealing with "unsafe" values (implemented in C.) By the way, I'm not sure I would call this existantial quantification, as it is only one-way. This looks more like a simple form of subtyping. Jacques Garrigue