caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Max Skaller <skaller@ozemail.com.au>
To: Mattias Waldau <mattias.waldau@tacton.se>
Cc: caml-list@inria.fr
Subject: ROverloading
Date: Sun, 17 Dec 2000 01:10:38 +1100	[thread overview]
Message-ID: <3A3B77DE.162549AD@ozemail.com.au> (raw)
In-Reply-To: <HDEEKOMJILGEIHIMAPCDCEBJDMAA.mattias.waldau@tacton.se>

Mattias Waldau wrote:

> >> I would like to note that type inference (i.e. code without
> >> annotations) helps a lot when developing programs: the annotation free
> >> code is not only easier to write but also easier to maintain since it
> >> is kind of ``auto-adaptative'' and resistant to reorganisations and
> >> names modifications.
> 
> If this were important, we shouldn't have different operators for * and *.
> I had to change a program from integers to float recently, and it isn't fun
> at all.

	Overloading is, perhaps unfortunately, more or less
mandatory in the long run, perhaps not so much to support 'ad hoc
polymorphism'
as to relieve the programmer of learning lots of names for
things. In Ocaml, learning + for int and +. for float isn't
so bad. But add in ten other integer representations, and we're rapidly
forced to resort to named prefix operators (i.e. function names).

	Unfortunately, overloading isn't quite so simple when 
you've also got type inference:

	let f a b = a + b in
	let x = f 1.0 2.0 in
	let y = f 1 2 in 

If we take 'f' to be monomorphic, then
the second call is in error, because the overloaded + in the
definition of 'f' doesn't determine it's type until x is
calculated. Otherwise, 'f' could be taken to define an overloaded
set of functions (somewhat like a C++ template) and the calculations
of x and y would call different specialisations .. but this rapidly
gets quite messy.

Felix supports overloading, but it works more easily because
functions must be explicitly typed. Nevertheless it is sometimes
necessary to explicitly resolve an overload:

	function f(a:int):int { ..}
	function f(a:float):float { ..}
	val g = f of (int); // which f?

because there is inference of val's and var's, and, even without that:

	function g(f:int->int):int { .. }
	function g(f:float->float):float { .. }
	.. g(f of (int)) .. //which g? depends on which f!


-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net



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

Thread overview: 31+ 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         ` Functions must be explicitly typed, (was Same label in different types, how do people solve this?) Mattias Waldau
2000-12-13  0:51           ` 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                 ` John Max Skaller [this message]
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
2000-12-18 15:27 ROverloading Dave Berry
2000-12-19  6:45 ` ROverloading 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=3A3B77DE.162549AD@ozemail.com.au \
    --to=skaller@ozemail.com.au \
    --cc=caml-list@inria.fr \
    --cc=mattias.waldau@tacton.se \
    /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).