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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id F008ABB83 for ; Thu, 11 May 2006 17:49:17 +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 k4BFnHse023277 for ; Thu, 11 May 2006 17:49:17 +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 RAA06975 for ; Thu, 11 May 2006 17:49:16 +0200 (MET DST) Received: from lion.seas.upenn.edu (LION.SEAS.upenn.edu [158.130.12.194]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k4BFnFpZ023266 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 11 May 2006 17:49:16 +0200 Received: from [192.168.19.128] (LVN514-2.cis.upenn.edu [158.130.50.247]) (authenticated bits=0) by lion.seas.upenn.edu (8.13.6/8.12.10) with ESMTP id k4BFn7JZ030532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 11 May 2006 11:49:14 -0400 Message-ID: <44635CD6.8090802@cis.upenn.edu> Date: Thu, 11 May 2006 11:48:38 -0400 From: Geoffrey Alan Washburn User-Agent: Thunderbird 1.5.0.2 (X11/20060420) MIME-Version: 1.0 Newsgroups: gmane.comp.lang.caml.inria To: Jacques Garrigue Cc: caml-list@inria.fr Subject: Re: OO design References: <44621204.4020601@cs.washington.edu> <44628062.6010509@cis.upenn.edu> <20060511.152118.223263747.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20060511.152118.223263747.garrigue@math.nagoya-u.ac.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44635CFD.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44635CFB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; upenn:01 monadic:01 monadic:01 ocaml:01 statically:01 environement:01 mutable:01 stays:98 wrote:01 encode:01 alan:01 jacques:01 simpler:02 garrigue:03 latter:03 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 Jacques Garrigue wrote: > From: Dan Grossman > >> A monadic approach (where each >> operation would return a "new" file) or linearity appears necessary for >> the latter. > > And you can perfectly encode the monadic approach in ocaml. > In our case, we need the type of the monad to keep information about > open and closed files. > I include such a solution, which ensures the safety of file accesses, > at the end of this post. Note that file handles are indexed > statically, but you can use as many as you wish. > > It should be safe with references (there is no file handle that you > can keep around, everything stays in the monad.) But beware of fancy > extensions, like continuations, that would allow you to capture your > environement, included files that were open when you created the > continuation... Ah, good point. I hadn't been thinking about it quite correctly when I was doing the thought experiment, but a simpler way to look at it is that "the IO monad and the (implicit) state monad commute". Therefore, mutable references won't actually cause a problem.