caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Type Inference and Overloading
@ 2006-04-10  8:51 Tom Primožič
  2006-04-10 11:57 ` [Caml-list] " skaller
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tom Primožič @ 2006-04-10  8:51 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]

I would like to pose one really perverse question (perverse because it
mentions overloading).

I have done a lot of thinking over the subject of type inference with
overloading. I have also read a lot, however, no paper satisfied me. I don't
like constraints (neither
GCaml<http://web.yl.is.s.u-tokyo.ac.jp/%7Efuruse/gcaml/>nor System
CT <http://citeseer.ist.psu.edu/camarao99type.html> like) as i find them too
difficult for the user to understand.

I have been trying to think of another mechanism for inferring overloaded
types, but have yet been unsuccessful.

Does anyone have any idea what kind of algorithm and structures would the
compiler need to deploy to correctly infer the types for these functions:

a : int -> float -> int
a : float -> int -> int

b : int -> int -> int
b : float -> int -> int

let f1 x y =
      let z = a x y in
      b x y + z

let f1 x y z =
      let r = a x z in
      let s = a z y in
      b x y + r * s

It is pretty clear to the human that f1 has type float -> int -> int,
however, it takes a bit more thinking to realize that the type of f1 is int
-> int -> float -> int. However, while human sees the whole "program" in one
glance, the computer cannot perceive a picture as a whole. Thus, some
supposedly pretty complicated algorithm should be used.

Anyone has any idea?

Tom

[-- Attachment #2: Type: text/html, Size: 2506 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-04-11 17:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-10  8:51 Type Inference and Overloading Tom Primožič
2006-04-10 11:57 ` [Caml-list] " skaller
2006-04-10 13:42 ` Andrej Bauer
2006-04-10 14:06 ` Brian Hurt
2006-04-10 14:43   ` Tom Primožič
2006-04-11 16:11 ` Stefan Monnier

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).