Function overloading in OCaml

Viewed 4238

I have defined some types:

type box = Box of int
type table = Table of int
type compare_result = Lt | Eq | Gt

It seems that in OCaml, we can't define 2 functions with same name but different types of arguments:

let compare (a: box) (b: box): compare_result = (...)
let compare (a: table) (b: table): compare_result = (...)

let res_box = compare (Box 1) (Box 2) in (* which is supposed to call the first funciton *) 
let res_table = compare (Table 1) (Table 2) in (* which is supposed to call the second function *)

So could anyone tell me what is the alternative in OCaml to do this? Do we have to name these 2 functions differently?

1 Answers
Related