From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 3C692BB81 for ; Thu, 9 Dec 2004 14:12:53 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB9DCqd2022706 for ; Thu, 9 Dec 2004 14:12:52 +0100 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 OAA28073 for ; Thu, 9 Dec 2004 14:12:52 +0100 (MET) Received: from will.iki.fi (will.iki.fi [217.169.64.20]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iB9DCpnJ022703 for ; Thu, 9 Dec 2004 14:12:52 +0100 Received: from acerf.exomi.com (fa-3-0-0.fw.exomi.com [217.169.64.99]) by will.iki.fi (Postfix) with ESMTP id 640F61E; Thu, 9 Dec 2004 15:12:51 +0200 (EET) Subject: Re: [Caml-list] Re: environment idiom From: Ville-Pertti Keinonen To: Richard Jones Cc: caml-list@inria.fr In-Reply-To: <20041209090911.GA21478@annexia.org> References: <9410EC84C0872141B27A2726613EF45D02A52E08@psmrdcex01.psm.pin.safeco.com> <20041209090911.GA21478@annexia.org> Content-Type: text/plain Date: Thu, 09 Dec 2004 15:12:25 +0200 Message-Id: <1102597946.90156.19.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.0.3 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 41B84F54.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41B84F54.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 compile-time:01 hash:01 run-time:01 compile-time:01 run-time:01 ocaml:01 statically:01 hash:01 val:01 mli:01 compilation:01 idiom:01 explicitly:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On Thu, 2004-12-09 at 09:09 +0000, Richard Jones wrote: > Just an observation here: > > The object method seems to be compile-time safe, whereas the hash > method seems to require run-time checks which could fail. Am I right > in thinking this? If so, the compile-time safe version is infinitely What run-time checks? OCaml is statically typed, it has no run-time type checking. Only things like array bounds are checked at run-time. The hash method is typed similarly to the following: # let x = ref `A;; val x : _[> `A ] ref = {contents = `A} # x := `B;; - : unit = () # x;; - : _[> `A | `B ] ref = {contents = `B} However, when using such things in real programs you must specify the final type explicitly (e.g. in the .mli file) in order to give a definite type for the variable in the module (since the above obviously isn't safe across compilation units).