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 578D8D45F for ; Tue, 1 Nov 2005 09:34:50 +0100 (CET) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA18Ym6X020217 for ; Tue, 1 Nov 2005 09:34:49 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by smtp3.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jA18YPGD041272; Tue, 1 Nov 2005 19:04:26 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] Type inference problem From: skaller To: Jonathan Roewen Cc: caml-list@yquem.inria.fr In-Reply-To: References: Content-Type: text/plain Date: Tue, 01 Nov 2005 19:34:25 +1100 Message-Id: <1130834065.7552.71.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 436728A8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 inference:01 stdlib:01 ocamlc:01 rec:01 buf:01 rec:01 buf:01 bug:01 'int':01 wrote:01 sourceforge:01 complains:01 expression:01 int: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 Tue, 2005-11-01 at 20:58 +1300, Jonathan Roewen wrote: > Hi, > > I can't figure out what's wrong with my code =( > > It's on a paste site, so will only last about 24 hours or so. > http://rafb.net/paste/results/Uux57B97.html > > jonathan@moonbeam:~/dst/stdlib$ ocamlc VFS.ml > File "VFS.ml", line 106, characters 3-6: > This expression has type int but is here used with type unit > > It -has- to return int ;-) But I have no idea where the type > constraint is coming from that wants it to return unit. Change it to > return unit, and where it's used complains it doesn't return type int > (so that constraint is correct). You could replace this line: let rec write data fd buf off len = with this one: let rec write data fd buf off len : int = to find out. But I can tell you anyhow the bug is here let rec read data fd buf off len = if len + fd.offset > fd.size then read data fd buf off (fd.size - fd.offset); in the second line: if true then 1; will give the same error for the same reason: the above line is just shorthand for: if true then 1 else (); and the type of 1 and () disagree. In your case, the type of the 'then' branch is infered to be 'unit' .. and then you go and return an 'int' at the end of the function -- there is no 'conflict' until that point. Declaring the return type will catch the error where it really is, the second line of the read function. You can fix this by: if len + fd.offset > fd.size then ignore(read data fd buf off (fd.size - fd.offset)); or by if len + fd.offset > fd.size then let _ = read data fd buf off (fd.size - fd.offset) in (); -- John Skaller Felix, successor to C++: http://felix.sf.net