בתאריך יום ג׳, 19 במרץ 2019, 0:41, מאת Greg Ewing ‏<
greg.ew...@canterbury.ac.nz>:

> Rémi Lapeyre wrote:
>
> > You can make "inferences from the way things are used". But the
> > comparison with maths stops here, you don’t make such inferences because
> your
> > object must be well defined before you start using it.
>
> In maths texts it's very common to see things like 'Let y = f(x)...'
> where it's been made clear beforehand (either explicitly or implicitly)
> what type f returns.
>
> That's completely analogous to inferring the type bound to a Python
> name from an assignment statement.
>
>  > You can track types with
> > comments but you need to comment each line.
>
> No, you don't, because most lines in most programs allow types to
> be inferred. The reason that things like MyPy are possible and
> useful is that Python programs in practice are usually well-typed.
>
> > In maths, an given object is not duck because it quacks and walks like
> > a duck, it’s
> > either part of the set of all ducks, or not.
>
> But there's no restriction on how you define the set of all ducks.
> It could be "the set of all things that quack". Duck typing is
> totally possible in mathematics, even common.
>
> For example, in linear algebra the ducks are "anything you can
> apply a linear operator to". That can cover a surprisingly large
> variety of things.
>
> > But the equation is only meaningful in a given context. Asking whether
> > f: x -> 1/x
> > is differentiable is only meaningful if we know whether x is in R, C,
> > [1; +oo[...
>
> That depends on what you want to say. You can say "let f be a
> differentiable function" and then go on to talk about things that
> depend only on the differentiability of f, without knowing
> exactly what types f operates on. Then later you can substitute
> any function you know to be differentiable, and all of those
> thing will be true for it.
>
> Mathematicians abstract things this way all the time. Groups,
> fields, vector spaces, etc. are all very abstract concepts,
> defined only as a set of objects having certain properties.
> If that's not duck typing, I don't know what is.
>

Technically, that's structural typing. Duck typing is only relevant when
there is some kind of control flow, and things need not always have all the
properties in question.

But I don't think this difference is that important in the context.

Elazar
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to