From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA26767; Fri, 2 Apr 2004 15:41:33 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA27505 for ; Fri, 2 Apr 2004 15:41:32 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from troyes.dyndns.org (m48.net81-65-220.noos.fr [81.65.220.48]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i32DgHjq020954 for ; Fri, 2 Apr 2004 15:42:18 +0200 Received: from [10.0.1.201] (localhost [127.0.0.1]) by troyes.dyndns.org (Postfix) with ESMTP id 631125959F for ; Fri, 2 Apr 2004 15:41:26 +0200 (CEST) Mime-Version: 1.0 Message-Id: Date: Fri, 2 Apr 2004 15:41:26 +0200 To: caml-list@inria.fr From: Paul Guyot Subject: [Caml-list] failwith, raise and type inference Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; failwith:01 inference:01 3.07:01 failwith:01 avalue:01 avalue:01 val:01 val:01 rendez-vous:99 newton:99 dict:01 dict:01 ocaml:01 rec:01 rec:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 26 Hello, My students came up with a behavior of ocaml I couldn't explain. I have exactly the same result with 3.07pl2 and a fresh copy checked out from CVS. >let rec f1 key dict = > match dict with > [] -> failwith "The key " ^ key ^ " could not be found" > | (aKey, aValue)::tail -> > if (aKey = key) > then aValue > else f1 key tail;; is of type: val f1 : string -> (string * string) list -> string = while: >exception SomeException of string;; > >let rec f2 key dict = > match dict with > [] -> raise (SomeException key) > | (aKey, aValue)::tail -> > if (aKey = key) > then aValue > else f2 key tail;; is of type: val f2 : string -> (string * 'a) list -> 'a = Considering that failwith is of type string -> 'a and raise of type exn -> 'a, I couldn't figure out why the correct type for f is only infered with raise. Any idea? Paul -- Philosophie de baignoire - consultations sur rendez-vous. NPDS/NewtonOS: http://newton.kallisys.net:8080/ Apache/FreeBSD: http://www.kallisys.com/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners