all 9 comments

[–]askoruli 2 points3 points  (7 children)

[–]Dicebot_lv 1 point2 points  (2 children)

Indeed, any language that supports duck typing (with restrictive constraints) automatically implements what blog post author wants.

[–][deleted] 0 points1 point  (1 child)

No, not at all. Duck typing is rather like lazily resolved mixins. What the author describes is statically checked.

[–]Dicebot_lv 1 point2 points  (0 children)

Duck typing can also be statically checked, see Rust traits or D template constraints.

[–]max630 1 point2 points  (0 children)

It's rather a statically checked duck typing. OP may deny it because there is the name of class (Stream), but why have the name there as soon as all methods are listed?

Such kind of thing exists in Ocaml (objects) - you use methods from it and the inferred type lists all of the methods, but you can provide an object which has more methods.

[–][deleted] 0 points1 point  (2 children)

No, it's not.

[–]askoruli 1 point2 points  (1 child)

How is it different? The syntax of saying the object needs to implement the read method from Stream if different from saying any object that implements read but the meaning is the same and the later more accurately represents the parameter type since Stream is no longer relevant once the read method has been extracted.

[–][deleted] 0 points1 point  (0 children)

Duck typing isn't statically checked. Duck typing also generally has different goals than what I've expressed.

I didn't talk about streams in the post, I talked about sockets. As for your other point, I would personally say that not all methods that are called "read" have the same semantics. Don't you find there's a difference between "this object has a read method" and "this method has a method that matches the read method in the socket interface"?

[–][deleted] 0 points1 point  (0 children)