Subtle bug with the OO post: proto self { ... } is parsed as proto (self { ... }), but what is meant is (proto self) { ... }. With the former, we can't call overridden methods from the overriding object.
Minimal example:
data Thing = Thing {
a :: String,
b :: String
} deriving (Show)
proto :: Thing -> Thing
proto self = Thing {
a = "original a " ++ b self,
b = "original b"
}
base :: Thing
base = fix proto
proto' :: Thing -> Thing
proto' self = (proto self) { b = "new b" }
derived :: Thing
derived = fix proto'
-- without explicit parens, `b derived` wrongly returns "original b";
-- with, it returns "new b"
Subtle bug with the OO post:
proto self { ... }
is parsed asproto (self { ... })
, but what is meant is(proto self) { ... }
. With the former, we can't call overridden methods from the overriding object.Minimal example: