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 035F5D45F for ; Tue, 1 Nov 2005 09:50:33 +0100 (CET) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jA18oUNA021399 for ; Tue, 1 Nov 2005 09:50:31 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id jA18o8Cj069254; Tue, 1 Nov 2005 19:20:08 +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:50:07 +1100 Message-Id: <1130835007.7552.88.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 43672C56.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 inference:01 compiler:01 ocaml:01 elif:01 unify:01 elif:01 ocaml:01 recursive:01 annotations:01 inference:01 traceback:01 ...:98 ...:98 wrote: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 21:19 +1300, Jonathan Roewen wrote: > Ohh, I found it =) If without else, where return type of if is non-unit. > > Is it possible compiler could flag this error a bit better? IE: when > if returns non-unit, and there's no else? Ocaml uses some shortcuts because it doesn't distinguish functional from procedural code. Felix does. It uses: if c1 then e1 [elif c2 then e2 ..] else ee endif for functional code -- the 'else' is mandatory, and the expressions e1, e2 .. ee may not be void, and must unify. Procedural code uses if c do ... ; ... ; [elif ... ; ... ; .. ] [else ..; .. ; ] done; and all the ... ; entries must be (manifestly) of type void. Now, the problem with your request is that Ocaml is *deducing* the type of read .. it is in fact unit, so the condition for reporting an error you state would NOT catch any error because there isn't one. On the other hand if you obey a reasonable style rule: "always annotate the return type of a recursive function" then Ocaml would have done precisely what you asked for. Whenever you get a type error you don't understand *add type annotations* to try to localise the problem. I would restate your request like this: when the inference engine reports a type error, it should provide a full traceback of all parts of the code that lead it to deduce the conflicting types. I expect the error message would be hard to read.. and also that it would greatly complicate the inference engine to actually keep track of where all the inferences come from -- not sure on either point. -- John Skaller Felix, successor to C++: http://felix.sf.net