Op 2005-12-14, Magnus Lycka schreef <[EMAIL PROTECTED]>: > [EMAIL PROTECTED] wrote: >> Magnus Lycka wrote: >> >>>I don't really know Haskell, so I can't really compare it >>>to Python. A smarter compiler can certainly infer types from >>>the code and assemble several implementations of an >>>algorithm, but unless I'm confused, this makes it difficult >>>to do the kind of dynamic linking / late binding that we do in >>>Python. How do you compile a dynamic library without locking >>>library users to specific types? >> >> I don't know. I am learning Haskell(and Python too), long way to go >> before I would get into the the usage you mentioned, if ever, be it >> Haskell or Python. > > Huh? I must have expressed my thoughts badly. This is trivial to > use in Python. You could for instance write a module like this: > > ### my_module.py ### > import copy > > def sum(*args): > result = copy.copy(args[0]) > for arg in args[1:]: > result += arg > return result > > ### end my_module.py ### > > Then you can do: > > >>> from my_module import sum > >>> sum(1,2,3) > 6 > >>> sum('a','b','c') > 'abc' > >>> sum([1,2,3],[4,4,4]) > [1, 2, 3, 4, 4, 4] > >>> > > Assume that you didn't use Python, but rather something with > static typing.
That depends on what you would call static typing. Suppose we would add type declarations in python. So we could do things like int: a object: b Some people seem to think that this would introduce static typing, but the only effect those staments need to have is that each time a variable is rebound an assert statement would implicitly be executed, checking whether the variable is still an instance of the declared type. (Assuming for simplicity that all classes are subclasses of object so that all objects are instances of object.) > How could you make a module such as my_module.py, In the above scenario in just the same way as in python. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list