<br><br><div class="gmail_quote"><div dir="ltr">בתאריך יום ג׳, 19 במרץ 2019, 0:41, מאת Greg Ewing <<a href="mailto:greg.ewing@canterbury.ac.nz">greg.ewing@canterbury.ac.nz</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Rémi Lapeyre wrote:<br>
<br>
> You can make "inferences from the way things are used". But the<br>
> comparison with maths stops here, you don’t make such inferences because your<br>
> object must be well defined before you start using it.<br>
<br>
In maths texts it's very common to see things like 'Let y = f(x)...'<br>
where it's been made clear beforehand (either explicitly or implicitly)<br>
what type f returns.<br>
<br>
That's completely analogous to inferring the type bound to a Python<br>
name from an assignment statement.<br>
<br>
> You can track types with<br>
> comments but you need to comment each line.<br>
<br>
No, you don't, because most lines in most programs allow types to<br>
be inferred. The reason that things like MyPy are possible and<br>
useful is that Python programs in practice are usually well-typed.<br>
<br>
> In maths, an given object is not duck because it quacks and walks like<br>
> a duck, it’s<br>
> either part of the set of all ducks, or not.<br>
<br>
But there's no restriction on how you define the set of all ducks.<br>
It could be "the set of all things that quack". Duck typing is<br>
totally possible in mathematics, even common.<br>
<br>
For example, in linear algebra the ducks are "anything you can<br>
apply a linear operator to". That can cover a surprisingly large<br>
variety of things.<br>
<br>
> But the equation is only meaningful in a given context. Asking whether<br>
> f: x -> 1/x<br>
> is differentiable is only meaningful if we know whether x is in R, C,<br>
> [1; +oo[...<br>
<br>
That depends on what you want to say. You can say "let f be a<br>
differentiable function" and then go on to talk about things that<br>
depend only on the differentiability of f, without knowing<br>
exactly what types f operates on. Then later you can substitute<br>
any function you know to be differentiable, and all of those<br>
thing will be true for it.<br>
<br>
Mathematicians abstract things this way all the time. Groups,<br>
fields, vector spaces, etc. are all very abstract concepts,<br>
defined only as a set of objects having certain properties.<br>
If that's not duck typing, I don't know what is.<br></blockquote></div><div><br></div><div>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. </div><div><br></div><div>But I don't think this difference is that important in the context. </div><div><br></div><div>Elazar </div>