From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA28698 for caml-red; Thu, 14 Dec 2000 19:17:32 +0100 (MET) 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 UAA17616 for ; Tue, 12 Dec 2000 20:24:47 +0100 (MET) Received: from tor.abc.se (ns.abc.se [195.17.72.11]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eBCJOk512201 for ; Tue, 12 Dec 2000 20:24:46 +0100 (MET) Received: from gateway (dialup-28 [195.17.73.28]) by tor.abc.se (8.9.3+Sun/8.9.3) with SMTP id UAA11049; Tue, 12 Dec 2000 20:24:37 +0100 (MET) From: "Mattias Waldau" To: "John Max Skaller" , "Caml-List" Subject: Functions must be explicitly typed, (was Same label in different types, how do people solve this?) Date: Tue, 12 Dec 2000 20:24:25 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal In-Reply-To: <3A3663B5.412BECE2@ozemail.com.au> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Sender: weis@pauillac.inria.fr > In Felix, I compromised: functions must be explicitly typed > when declared, but values don't: > > function f(a:int): int { val b = a; return b; } Which I think is an good idea. I normally type the functions in Ocaml, but I don't type the local variables. Then I will get the type-error message at the function definition and not at references to the function. In the following example I forgot the 2nd argument to f2 in g. Now the compiler will complain when the function g is called from h and point at h for the error. THIS IS TOO LATE! let f2 x y = x * y let g x = f2 x let h x = 2 * g x ^^^ This expression has type int -> int but is here used with type int However, if I had wrote let f2 (x:int) (y:int) = x * y let g (x:int) : int = f2 x ^^ This expression has type int -> int but is here used with type int let h (x:int) = 2 * g x I would have gotten a compiler error directly since the type of g isn't int, it is the closure 'f2 x'. AND NOW I CAN CORRECT THE ERROR DIRECTLY I don't really see the use of infering types for functions. It works for one person hacks, like compilers, interpreters, theorem provers, but it doesn't scale well to programs with many programmers involved. The types of the function is vital information when you try to understand the code. And putting this information in a separate file (.mli) for some of the functions (the public ones) isn't a very good solution. If you required that the arguments where typed, wouldn't it be possible to get rid of the distinction of * and *., and infer if it is float or int? It is a big pain today changing from int to float in a program, in non-ML languages you just make 'M-x query-replace "int" "float"' /mattias