Why I love python.
brian at sweetapp.com
Fri Aug 13 12:13:48 CEST 2004
Erik de Castro Lopo wrote:
>> def sum (a, b):
>> return a + b
>>How can the compiler know what code to produce?
> I know of at least one language which has solved this problem, Ocaml
> Its called type inferencing and since there is at least one working
> implementation, it can't be THAT hard.
You are comparing apples and oranges. The programmer provides OCaml
with additional information that allows it to interfer the type.
Looking at the example above, the OCaml equivalent would be:
let sum x,y = x + y;;
But this function would only work for integers because the * operator
only applies to integers. If you wanted to multipy floats then you
let sum x,y = x +. y;;
So there is no magic in OCaml, just a different way of providing type
More information about the Python-list