Python 1.6 The balanced language
Suchandra Thapa
ssthapa at harper.uchicago.edu
Mon Sep 4 01:47:11 EDT 2000
Neel Krishnaswami <neelk at brick.cswv.com> wrote:
>Suchandra Thapa <ssthapa at harper.uchicago.edu> wrote:
>> Neel Krishnaswami <neelk at brick.cswv.com> wrote:
>> >Suchandra Thapa <ssthapa at harper.uchicago.edu> wrote:
>> >>
>> >> Actually I think clean is a pure functional oo language. It's just
>> >> that being oo seems to imply that you have some state to your
>> >> objects. Not sure anyone would get around this paradox.
>> >
>> >No, the distinguishing features of OO are that a) subtyping exists,
>> >and b) the types of objects are used to do dynamic dispatch. Mutable
>> >state is not necessary -- in both Dylan and Ocaml, it's common to
>> >write code in an "object-functional" style, with lots of objects but
>> >no mutation.
>>
>> I forgot about the existence of OCaml when I was writing the post
>> but ML has imperative features and so is not a pure functional language.
>
>I usually think of any of the ML/Scheme clan as functional languages,
>and specify "pure" when I want to limit myself to Clean or Haskell.
>
>> The example you gave just illustrated dispatch on types.
>
>Specifically it illustrated dispatch on based on *subtypes*; that is
>it looked at the /runtime/ type of the object to decide which method
>body to call. So in a typed Python, take the function
>
>def squarelen(lst: List) -> Integer:
> return len(lst) * len(lst)
>
>If you pass squarelen() a SizedList, then it will call the
>SizedList.__len__ method, not the List.__len__ method.
Alright I think I understand your point here. But the same thing
seems to be possible using type classes ala Haskell. E.g. define a type
class that supports a len and declare List and SizedList as instances of
this type class.
>> Incidentally, what do you mean by dynamic dispatch? ML and its
>> dialect OCaml are statically typed and the compiler chooses which
>> function to call at compile time. Would you consider OCaml to be OO
>> then?
>
>The OO extension to Ocaml makes sure that a method exists for every
>message send, but it doesn't determine which method to call at compile
>time. So no "message not understood" errors can happen, but the
>specific method body is chosen based on the runtime type. This is what
>I mean by dynamic dispatch. It's a form of overloading constrained by
>the type.
Alright, I was under the impression that OCaml was like ML and had
only static type checking. Therefore I was slightly confused on whether
dynamic dispatch was used in a different sense then the one I expected.
>> But getting back to OO, I'm not sure how the essentials of OO that
>> you put forward mesh with a pure functional approach. In other
>> words suppose I had a method bar belonging to class foo. How would
>> I distinguish using foo.bar from using another function baz that
>> took the same parameters and returned the same results?
>
>I'm don't I understand this question.
Essentially, I'm asking what does objects and classes add to a pure
functional language. Since methods for a class are equivalent to functions
that take objects of a class and return another object of the same class,
what do you gain by introducing OOP to a pure functional language?
>Objects with different internal values would behave differently. It's
>just that instead of modifying an object we create new ones. Eg,
>imagine that every Python object were immutable, like integers and
>strings.
But there wouldn't be any link between class objects and their methods in
a pure functional language aside from a logical one in the programmer's mind.
Methods in a class would have to explicitly be passed class objects. In effect
you're essentially working with structs and functions on them.
More information about the Python-list
mailing list