3 ms·
There are languages (libraries) that solve it. For reference, check Clojure's multimethods and OCaml's polymorphic variants.
by chenglou 10y ago
There are languages (libraries) that solve it. For reference, check Clojure's multimethods and OCaml's polymorphic variants.
- smallnamespace 10y agoThe tradeoff is that techniques like multimethods significantly weaken the contract that people normally expect from methods/classes. For example, if I'm writing a normal Java class, I know where I go to find methods dealing specifically with instances Foo (namely Foo and its children and direct users); with multimethods, it's more likely that there is some multimethod out there in an unrelated class that looks for instances of Foo.
- eru 10y agoGood tooling (think something along the lines of Hoogle) can help here.
- edwintorok 10y agoThe OCaml solution with polymorphic variants: http://www.math.nagoya-u.ac.jp/~garrigue/papers/fose2000.html http://www.math.nagoya-u.ac.jp/~garrigue/papers/fose2000.htm.... A very good summary of that paper is available here: http://lambda-the-ultimate.org/node/1518#comment-17566 http://lambda-the-ultimate.org/node/1518#comment-17566 Another alternative based on recursive modules: http://www.math.nagoya-u.ac.jp/~garrigue/papers/#privaterows http://www.math.nagoya-u.ac.jp/~garrigue/papers/#privaterows