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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 28818BC37 for ; Tue, 9 Feb 2010 09:24:23 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak8CAOeqcEvRVdzVimdsb2JhbACbCDwBAQEKCQwHEQWsVY9dgkOCEQSOGQ X-IronPort-AV: E=Sophos;i="4.49,435,1262559600"; d="scan'208";a="56436610" Received: from mail-fx0-f213.google.com ([209.85.220.213]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Feb 2010 09:24:22 +0100 Received: by fxm5 with SMTP id 5so225145fxm.17 for ; Tue, 09 Feb 2010 00:24:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.27.70 with SMTP id h6mr5185237fac.50.1265703862312; Tue, 09 Feb 2010 00:24:22 -0800 (PST) In-Reply-To: <20100209.123813.39168535.garrigue@math.nagoya-u.ac.jp> References: <14cf844b1002081907y2900c313q97ae0cb6f4c92394@mail.gmail.com> <20100209.123813.39168535.garrigue@math.nagoya-u.ac.jp> Date: Tue, 9 Feb 2010 08:24:22 +0000 Message-ID: <30961e501002090024l18a9b458y8b3a7bd910626d38@mail.gmail.com> Subject: Re: [Caml-list] Preventing values from escaping a context From: Miles Sabin To: Jacques Garrigue Cc: rich.neswold@gmail.com, caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; compiler:01 uniqueness:01 compiler:01 uniqueness:01 cheers:01 skype:01 wrote:01 caml-list:01 short:01 linear:02 off-topic:02 epfl:02 epfl:02 parameter:02 parameter:02 On Tue, Feb 9, 2010 at 3:38 AM, Jacques Garrigue wrote: > From: Rich Neswold >> My question is this: Is there a way to make the compiler reject a function >> parameter from returning the context parameter? For instance, the identity >> function should be disallowed since the context is invalid outside the scope >> of 'usingContext'. It's true that a returned context would be unusable, >> since its resources are gone, but it would be nice to prevent contexts from >> escaping the 'usingContext' function entirely. > > The short answer is no. > Types are not sufficient to prevent values from escaping. I appreciate that mention of Scala is borderline off-topic on this list, however that's a very broad negative statement, so broad counterexamples seem appropriate ... ;-) Philippe Haller of EPFL is working on a uniqueness types extension of Scala which provides exactly this, packaged as a compiler plugin for scalac (my hope is that it will be rolled into the main scala distribution during the 2.8.x series, so this isn't solely academic exercise). An example here, http://tinyurl.com/ya6f7jv and the corresponding compiler-time error, http://tinyurl.com/yzgnus5 Full details can be found in his technical report here, http://lamp.epfl.ch/~phaller/capabilities.html Scala isn't the only language which supports linear/uniqueness types, however it's the only which does and has some prospect of becoming mainstream. Cheers, Miles -- Miles Sabin tel: +44 (0)7813 944 528 skype: milessabin http://www.chuusai.com/ http://twitter.com/milessabin