From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 8A10DBC8C for ; Tue, 25 Jan 2005 23:52:28 +0100 (CET) Received: from woodstock.1969.ws (64-215-156-42.eosinc.net [64.215.156.42]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j0PMqRhq006147 for ; Tue, 25 Jan 2005 23:52:27 +0100 Received: (qmail 24145 invoked from network); 25 Jan 2005 22:32:05 -0000 Received: from karl.1969.ws (HELO ?10.3.2.15?) (10.3.2.15) by woodstock.1969.ws with SMTP; 25 Jan 2005 22:32:05 -0000 Message-ID: <41F6CE0A.1010301@1969.ws> Date: Tue, 25 Jan 2005 14:54:02 -0800 From: Karl Zilles Organization: 1969 Communications, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: yjc01@doc.ic.ac.uk Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] open_file References: <1106691570.41f6c5f250fdc@www.doc.ic.ac.uk> In-Reply-To: <1106691570.41f6c5f250fdc@www.doc.ic.ac.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41F6CDAB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 indirection:01 unix:01 int:01 string:03 string:03 let:03 let:03 file:08 file:08 buff:09 buff:09 content:89 content:89 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: yjc01@doc.ic.ac.uk wrote: > The code I came up with is as follows: I forgot to add, there is no reason to use a reference for buff: > > open Unix;; > > let file_reader = openfile "sudent.cd" [O_RDONLY] 0o640;; > let buff = ref "empty";; let buff = "empty";; > > let main () = > let file_content = read file_reader !buff 1 5 in let file_content = read file_reader buff 0 5 in > print_int file_content; > print_string !buff;; print_string buff;; > main (); This is because you are actually writing directly on the string, so there is no need for indirection.