Why I love python.
Brian Quinlan
brian at sweetapp.com
Fri Aug 13 06:13:48 EDT 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
>
> http://www.ocaml.org/
>
> 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
would write:
let sum x,y = x +. y;;
So there is no magic in OCaml, just a different way of providing type
information.
Cheers,
Brian
More information about the Python-list
mailing list