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 0CB40BB84 for ; Wed, 10 May 2006 20:44:02 +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 k4AIi1IO018427 for ; Wed, 10 May 2006 20:44:01 +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 UAA24289 for ; Wed, 10 May 2006 20:44:00 +0200 (MET DST) Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.10]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k4AIhwvS018417 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Wed, 10 May 2006 20:44:00 +0200 Received: (qmail 1537 invoked from network); 10 May 2006 18:43:57 -0000 Received: from shell2.sea5.speakeasy.net ([69.17.116.3]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 10 May 2006 18:43:57 -0000 Date: Wed, 10 May 2006 11:43:57 -0700 (PDT) From: brogoff To: Dan Grossman Cc: Geoffrey Alan Washburn , caml-list@inria.fr Subject: Re: [Caml-list] Re: OO design In-Reply-To: <44621204.4020601@cs.washington.edu> Message-ID: 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> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at concorde with ID 44623471.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4462346E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; val:01 val:01 enforces:01 overkill:01 ocaml:01 sig:01 -'a:01 struct:01 omitted:01 variants:01 model:01 sml:01 monadic:01 wrote:01 writes:01 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 On Wed, 10 May 2006, 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. I think phantom types are overkill for this kind of either/or interface. The method used in the OCaml library of having an in_channel and out_channel is straightforward enough. Phantom types would make more sense to me when you have files which can be read and written, with an interface like this module File : sig type (-'a) file val open_in : string -> [`In] file val open_out : string -> [`Out] file val open_inout : string -> [`In|`Out] file val read : [> `In ] file -> char val write : [> `Out ] file -> char -> unit val close : 'a file -> unit end = struct (* Implementation omitted *) end ;; Note that I used polymorphic variants or row types to model this, I'm not sure how to do this cleanly in SML. Of course, you could code it up as in_channel, out_channel, and inout_channel ;-) > A monadic approach (where each > operation would return a "new" file) or linearity appears necessary for > the latter. Yoann Padioleau's suggestion to use the Lisp approach (with-open-file) looks like the best approach for ML to me. -- Brian