[Python-ideas] [Wild Idea] Static Ducks

Masklinn masklinn at masklinn.net
Sun Sep 20 11:56:30 CEST 2009

On 20 Sep 2009, at 06:21 , Bruce Leban wrote:
I don't quite understand what you are trying to solve. Here's a related
> problem: One of the issues with duck typing is that something might  
> look
> sort of like a duck but isn't really and it would be nice to make it  
> easy to
> avoid using an object in a "half-baked" manner:
>    def playWithDuck(d):
>       d.walk()
>       d.quack()
> if someone calls playWithDuck(dog) then the dog's going to get  
> walked before
> trying to make the dog quack fails.

Note that with a structural type system (that of OCaml's objects for  
instance) this will work, the `playWithDuck` function will be inferred  
to take any subtype of < walk : unit; duck : unit > (or something like  
that) (basically, any object with a `walk` and a `quack` method (both  
returning nothing) will work).

More information about the Python-ideas mailing list