Re:Closures and Objects Are Equivalent
by alex_muscar on Monday April 13, 2015 @08:45AM
(#9367267)
Your approach does not support polymorphism.
What sort of polymorphism did you have in mind?
Re:Closures and Objects Are Equivalent
by alex_muscar on Monday April 13, 2015 @10:32AM
(#9367818)
Subtyping polymorphism
Consider this simple syntactic rule: `obj.x` <=> `obj("x")`. With this rule, the usual syntax for a method call, `obj.method(x)`, literally becomes the curried application of a closure, `obj("method")(x)`. You could also add a rule like `obj(x) = y` <=> `obj(set(x, y))`. Then you could define objects a bit like this:
All closures. And the nice thing with that scheme is that meta-programming and reflection become completely trivial. Control over the interface is total. What use is there for "real" objects in this situation?