From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0E68EBB91 for ; Fri, 28 Jan 2005 14:42:27 +0100 (CET) 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 j0SDgQ0G010987 for ; Fri, 28 Jan 2005 14:42:26 +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 OAA04386 for ; Fri, 28 Jan 2005 14:42:26 +0100 (MET) Received: from hedwig1.umh.ac.be (hedwig2.umh.ac.be [193.190.193.73]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0SDgNYB010983 for ; Fri, 28 Jan 2005 14:42:26 +0100 Received: from poincare (mail@poincare.swapping.umh.ac.be [10.102.100.35]) by hedwig1.umh.ac.be (8.13.1/8.13.1) with ESMTP id j0SDjjxd1196242; Fri, 28 Jan 2005 14:45:47 +0100 Received: from poincare ([127.0.0.1] helo=localhost ident=trch) by poincare with esmtp (Exim 3.36 #1 (Debian)) id 1CuWOC-0001WE-00; Fri, 28 Jan 2005 14:42:20 +0100 Date: Fri, 28 Jan 2005 14:42:18 +0100 (CET) Message-Id: <20050128.144218.80110994.Christophe.Troestler@umh.ac.be> To: "O'Caml Mailing List" Subject: Re: [Caml-list] Re: '_a From: Christophe TROESTLER In-Reply-To: <1106873838.12114.128.camel@pelican.wigram> References: <1106818474.6734.152.camel@pelican.wigram> <1106873838.12114.128.camel@pelican.wigram> Organization: Universite de Mons-Hainaut (http://math.umh.ac.be/an/) X-Spook: COSCO Nazi passwd CBNRC CipherTAC-2000 USDOJ EuroFed morse codes Crypto AG X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Operating-System: GNU/Linux (http://www.linux.org/) X-Mailer-URL: http://www.mew.org/ X-Mailer: Mew version 4.2rc1 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.1 (www dot roaringpenguin dot com slash mimedefang) X-Miltered: at concorde with ID 41FA4142.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41FA413F.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 christophe:01 troestler:01 christophe:01 troestler:01 umh:01 sourceforge:01 wrote:01 rec:01 endline:01 compiler:01 rec:01 endline:01 val:01 compiler: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 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, let find v l = let x = let rec f = function | [] -> raise Not_found | h :: t -> if h = v then raise Found else f t in try f l with Found -> 1 | Not_found -> 2 in print_endline (string_of_int x) has type "val find : 'a -> 'a list -> unit = ". (BTW, note that the equality is "=" in Caml.) 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 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. Regards, ChriS