Why I love python.

Erik de Castro Lopo nospam at mega-nerd.com
Fri Aug 13 09:18:48 EDT 2004


Brian Quinlan wrote:
> 
> You are comparing apples and oranges. 

Yes, Ocaml and Python are very different languages but ...

> The programmer provides OCaml
> with additional information that allows it to interfer the type.

But Ocaml does have parametric polymorphism, ...

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

Using ints and floats is a bad example because Ocaml has different
operators for float and int. A better example might be a function to 
do the Python eqivalent of

    string.join (list_of_strings, ", ")

Ie:

     (* The list version *)
     let rec comma_join lst =
	match lst with
		[] -> ""
	|	hd :: [] -> hd
	|	hd :: tl -> hd ^ ", " ^ (comma_join tl)
	;;

    (* The array version, an example only. *)
    let comma_join ary =
	comma_join (Array.to_list ary)
	;;


Ocaml has no problem differentiating two functions with the same
name by looking at how the function arguments are used and assuming 
the function is generic if insufficient information is available.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam at mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"One World, one Web, one Browser." - Microsoft promotion
"Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler



More information about the Python-list mailing list