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 7D38ABB91 for ; Fri, 28 Jan 2005 15:50:40 +0100 (CET) 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 j0SEoeoC003068 for ; Fri, 28 Jan 2005 15:50:40 +0100 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 PAA06157 for ; Fri, 28 Jan 2005 15:50:39 +0100 (MET) 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 j0SEobbK020492 for ; Fri, 28 Jan 2005 15:50:38 +0100 Received: from [192.168.1.200] (ppp205-248.lns1.syd3.internode.on.net [203.122.205.248]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id j0SEoYc2061481; Sat, 29 Jan 2005 01:20:35 +1030 (CST) Subject: Re: [Caml-list] Re: '_a From: skaller Reply-To: skaller@users.sourceforge.net To: Christophe TROESTLER Cc: "O'Caml Mailing List" In-Reply-To: <20050128.144218.80110994.Christophe.Troestler@umh.ac.be> References: <1106818474.6734.152.camel@pelican.wigram> <1106873838.12114.128.camel@pelican.wigram> <20050128.144218.80110994.Christophe.Troestler@umh.ac.be> Content-Type: text/plain Message-Id: <1106923834.23562.148.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 29 Jan 2005 01:50:34 +1100 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41FA5140.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41FA513D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 sourceforge:01 christophe:01 troestler:01 wrote:01 sourceforge:01 wrote:01 rec:01 endline:01 compiler:01 compiler:01 glebe:01 061:98 assert:01 nsw:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: On Sat, 2005-01-29 at 00:42, Christophe TROESTLER wrote: > On 28 Jan 2005, skaller wrote: > > > > let x = > > let rec f l -> | [] -> raise Not_found > > | h :: t -> if h == v then (raise Found; 0) else f t > > in try f l with Found -> 1 | Not_found -> 2 > > in print_endline (string_of_int x) > > > > where the compiler doesn't know f l cannot return, so it needs a > > useless '0' after the Found case to get the typing correct. > > Not quite, [] > Maybe you mean something like > > let cl file = > let fh = open_in file in > let nl = ref 0 in > try > while true do > let _ = input_line fh in > incr nl > done > with End_of_file -> !nl Thanks for a better example (well a right one has to better :) > where the [while] has type [unit] while [!nl] has type [int] and the > two cannot be unified. But this is because there is no way for the > compiler to know that a loop indeed never ends, so one has to tell: > > let cl file = > let fh = open_in file in > let nl = ref 0 in > try > while true do > let _ = input_line fh in > incr nl > done; > assert false > with End_of_file -> !nl > > With that everything is fine. Yes, that's a better solution too. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net