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 MAA19233; Tue, 4 Jun 2002 12:22:13 +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 MAA19226 for ; Tue, 4 Jun 2002 12:22:12 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g54AMBH17984; Tue, 4 Jun 2002 12:22:11 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA19220; Tue, 4 Jun 2002 12:22:11 +0200 (MET DST) Date: Tue, 4 Jun 2002 12:22:11 +0200 From: Pierre Weis To: =?iso-8859-1?Q?G=E9rard_Huet?= Cc: caml-list@inria.fr Subject: Re: [Caml-list] about Obj.magic Message-ID: <20020604122211.A18447@pauillac.inria.fr> References: <200206011742.TAA16993@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 1.0i In-Reply-To: ; from Gerard.Huet@inria.fr on Sun, Jun 02, 2002 at 05:17:17PM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Gerard, > Hum. For me, the most frequent use of Obj.magic is when I do input_value > of some > persistent data, and the corresponding meta theorem seems tough to me, > since it > involves a complicated state reasoning (status of the file system, > knowledge that the > contents of the file was not tampered with since it was created, > hopefully with output_value, knowledge that the current type environment > is consistent with the one > that prevailed when I did output_value, etc). You are right input_value is a dangerous primitive that is roughly speaking equivalent to Obj.magic, and this is reflected in its type scheme: # input_value;; - : in_channel -> 'a = Hence, you should not ``use of Obj.magic is when (you) do input_value'': you should instead try to tame a bit this (over) polymorphic type, for instance by defining specialized versions of input_value and output_value that are statically type related. To input/output values of type ty, I generally define two functions input_ty and output_ty defined as a pair of explicitely typed functions, as in: let (output_ty : out_channel -> ty -> unit), (input_ty : in_channel -> ty) = (fun oc x -> output_value oc x), (fun ic -> input_value ic);; This way, ``the current type environment is consistent with the one that prevailed when I did output_value'' is automatically verified (at least, in the most common case where value IOs are performed from within the same executable). On the other hand, file tampering seems to me out of reach of a type system (and a bit similar to moving around .cmo and .cmi files). > Since I do not have this meta-theorem, it happens to me occasionally > to get typically Segmentation fault. Without explicit Obj.magic, but > with its implicit use with input_value, which is to my view its most > frequent usage, hard to avoid if you want to manage persistent data. > Gérard You are perfectly right: value IOs is mandatory to easily manage persistent data. That's why we need a safe way to do it. I think this is the last ennoying glitch that remains in the Objective Caml system. Best regards, -- Pierre Weis INRIA, Projet Cristal, http://pauillac.inria.fr/~weis ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners