Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
"OCaml gives you only monomorphic methods in classes."
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-12-29 (00:36)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] "OCaml gives you only monomorphic methods in classes."
On Friday 28 December 2007 23:55:32 Gordon Henriksen wrote:
> Jon, consider the case of Java or C++ method (and function)
> overloading. This form of static dispatch is quite distinct from
> virtual method dispatch, and is indeed at odds with type inference.

I see. Still, the solution seems easy enough. Just treat the overloaded types 
as part of the function name:

  foo(int n)
  foo(float x)
  foo(string s)


  foo_int n
  foo_float x
  foo_string s

When you come across:


you look up the statically inferred type of "a" and just bail if it fails to 
match any of the overloads.

Generics are left alone:

  foo<T>(T x)


  foo (x : 'T)

Would that work?

Dr Jon D Harrop, Flying Frog Consultancy Ltd.