From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2AFA9BBFB for ; Tue, 21 Jun 2005 20:55:11 +0200 (CEST) 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 j5LItAI4009100 for ; Tue, 21 Jun 2005 20:55:10 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA02706 for ; Tue, 21 Jun 2005 20:55:10 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5LIt8G1008113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 21 Jun 2005 20:55:09 +0200 Received: from localhost (localhost [127.0.0.1]) by nexus.stwing.upenn.edu (Postfix) with ESMTP id 1EDE064971 for ; Tue, 21 Jun 2005 14:55:08 -0400 (EDT) Received: from nexus.stwing.upenn.edu ([127.0.0.1]) by localhost (nexus.stwing.upenn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04287-10 for ; Tue, 21 Jun 2005 14:55:07 -0400 (EDT) Received: from force.stwing.upenn.edu (force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (Postfix) with ESMTP id B9D4464970 for ; Tue, 21 Jun 2005 14:55:07 -0400 (EDT) Received: by force.stwing.upenn.edu (Postfix, from userid 5302) id 7D81031F10; Tue, 21 Jun 2005 14:55:07 -0400 (EDT) Date: Tue, 21 Jun 2005 14:55:06 -0400 From: William Lovas To: caml-list@inria.fr Subject: Re: [Caml-list] exception Failure and failwith Message-ID: <20050621185506.GA7604@force.stwing.upenn.edu> Mail-Followup-To: caml-list@inria.fr References: <42B7D0FD.5090305@barettadeit.com> <20050621090740.GA10021@yquem.inria.fr> <42B7F6E2.3010508@yahoo.it> <20050621113440.GA3794@yquem.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050621113440.GA3794@yquem.inria.fr> User-Agent: Mutt/1.5.6i X-Virus-Scanned: amavisd-new at stwing.upenn.edu X-Miltered: at concorde with ID 42B8628E.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42B8628C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; lovas:01 wlovas:01 stwing:01 caml-list:01 failwith:01 maranget:01 struct:01 minor:01 abbreviation:01 recursive:01 failwith:01 bool:01 typecheck:01 cheers:01 ...:98 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Tue, Jun 21, 2005 at 01:34:40PM +0200, Luc Maranget wrote: > > It's what I was afraid of. > > I got it. Anyway let me make a consideration: It would be nice to have a > > way (a fake module named Core,for example) to access the core types, > > exception and definitions in case someone shadows the original one. > > Why not, but frankly, I am not sure this can be done easily. Besides, > this would potentially break user code, for users who happen to have a > module named 'Core'. In fact, one could easily build such a "Core" module as a user, following Julien's advice: > > exception Prim_Failure = Failure > > > > to get rid of any further shadowing. Just take this to the next level with something like: module Core = struct exception Failure = Failure type 'a opt = 'a option = None | Some of 'a type 'a option = 'a opt (* ... *) end (Note the minor contortion: we have to introduce a fake name 'a opt in order to avoid creating a cyclic type abbreviation, since data type definitions are automatically recursive. But of course, you can skip the second step if you don't care about having a type called 'a Core.option) While tedious, it's the sort of thing you could add to as you discover new reasons to do so. This Core module would allow interactions like the following situation, which might conceivably arise due to careless shadowing: (* function defined over primitive 'a option *) let valOf = function | None -> failwith "valOf" | Some x -> x;; (* evil shadowing *) type 'a option = None of 'a | Some of int exception Failure of bool;; try valOf None with Failure s -> s;; (* doesn't typecheck *) try valOf Core.None with Failure s -> s;; (* doesn't catch Failure *) try valOf Core.None with Core.Failure s -> s;; (* works! *) cheers, William