caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Mattias Waldau" <mattias.waldau@abc.se>
To: "John Max Skaller" <skaller@ozemail.com.au>,
	"Caml-List" <caml-list@inria.fr>
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	[thread overview]
Message-ID: <HDEEKOMJILGEIHIMAPCDCEOLDLAA.mattias.waldau@abc.se> (raw)
In-Reply-To: <3A3663B5.412BECE2@ozemail.com.au>

> 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




  reply	other threads:[~2000-12-14 18:17 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-06 21:22 Same label in different types, how do people solve this? Mattias Waldau
2000-12-07 16:49 ` John Max Skaller
2000-12-07 18:34 ` Maxence Guesdon
2000-12-07 23:02 ` Gerd Stolpmann
2000-12-08  1:22 ` Jacques Garrigue
2000-12-08  9:31   ` Sven LUTHER
2000-12-08  9:36     ` Pierre Weis
2000-12-08  9:48       ` Sven LUTHER
2000-12-08 18:41       ` John Max Skaller
2000-12-08  9:40     ` Nicolas barnier
2000-12-08 16:36 ` Brian Rogoff
2000-12-11 17:19   ` Pierre Weis
2000-12-10 12:49 ` Mattias Waldau
2000-12-11 18:23   ` Chris Hecker
2000-12-11 19:17     ` Pierre Weis
2000-12-12 10:02       ` Sven LUTHER
2000-12-12  3:25     ` Chet Murthy
2000-12-12 17:43       ` John Max Skaller
2000-12-12 19:24         ` Mattias Waldau [this message]
2000-12-13  0:51           ` Functions must be explicitly typed, (was Same label in different types, how do people solve this?) John Max Skaller
2000-12-15 10:13             ` Andreas Rossberg
2000-12-15 12:50             ` Frank Atanassow
2000-12-14 18:42           ` Stefan Monnier
2000-12-15 12:47             ` Pierre Weis
2000-12-15 13:39               ` Mattias Waldau
2000-12-15 23:37                 ` Brian Rogoff
2000-12-16 14:10                 ` ROverloading John Max Skaller
2000-12-15 21:51         ` Same label in different types, how do people solve this? Bruce Hoult
2000-12-12 17:19   ` John Max Skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=HDEEKOMJILGEIHIMAPCDCEOLDLAA.mattias.waldau@abc.se \
    --to=mattias.waldau@abc.se \
    --cc=caml-list@inria.fr \
    --cc=skaller@ozemail.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).