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 nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 7D987BB84 for ; Wed, 10 May 2006 20:34:56 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k4AIYu4Z021278 for ; Wed, 10 May 2006 20:34:56 +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 UAA24078 for ; Wed, 10 May 2006 20:34:55 +0200 (MET DST) Received: from mail5.sea5.speakeasy.net (mail5.sea5.speakeasy.net [69.17.117.7]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k4AIYrB2017367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 10 May 2006 20:34:54 +0200 Received: (qmail 29243 invoked from network); 10 May 2006 18:34:52 -0000 Received: from 67-40-193-41.tukw.qwest.net (HELO [192.168.1.115]) (shawnw@[67.40.193.41]) (envelope-sender ) by mail5.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 10 May 2006 18:34:52 -0000 Message-ID: <44623257.1060000@speakeasy.org> Date: Wed, 10 May 2006 11:35:03 -0700 From: Shawn User-Agent: Thunderbird 1.5.0.2 (Macintosh/20060308) MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] Re: OO design References: <53c655920605050235k64e70333je8df813239ea3c53@mail.gmail.com> <20060508.121743.65190532.garrigue@math.nagoya-u.ac.jp> <200605082329.36911.David.Teller@ens-lyon.org> <445FB9C7.4040703@cs.washington.edu> <446152CB.5010605@cis.upenn.edu> <44621204.4020601@cs.washington.edu> In-Reply-To: <44621204.4020601@cs.washington.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 44623250.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4462324D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; shawnw:01 val:01 val:01 enforces:01 monadic:01 wrote:01 writes:01 caml-list:01 char:01 char:01 compile:01 speakeasy:01 readable:01 hmm:02 checking:02 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 Dan Grossman wrote: > > I totally agree -- effects limit the class of protocols you can > enforce, but I believe (please correct me if I've missed a dirty > trick) the "simple stuff" still works fine. For example: > > type read; > type write; > type 'a file; > val open_r : string -> read file; > val open_w : string -> write file; > val write : write file -> char -> unit; > val read : read file -> char; > val close : 'a file -> unit; > > It enforces that you don't confuse your reads and writes, but *not* > that you don't use a file after you close it. A monadic approach > (where each operation would return a "new" file) or linearity appears > necessary for the latter. How can an approach like this handle files opened for reading and writing at the same time? Hmm. Maybe an OO approach? readable_file and writable_file classes, and a read_write_file that inherits from both. It'd be easy to add new file-like types too. I'm not normally a big fan of OO, but this is a place where it seems to make sense to use. Of course, it doesn't do anything about the compile time checking of attempts to use a closed file either.