On Tue, Apr 8, 2014 at 4:10 PM, Mason McGill <[email protected]>wrote:
> > This is what I was looking for; so if I understand you correctly, you > satisfy protocols by extending/monkey-patching Base. > An important distinction between this and monkey-patching is that if you create a new type and then only define methods for which one of the arguments must be of that type, you are never clobbering functionality that someone else defined. We don't enforce that, but it's best practice not to redefine existing functionality. Fortunately, multiple dispatch makes this easy to do without resorting to monkey patching. > This seems reasonable, but what do you do when you want to define your own > protocol (e.g. Classifier), and Base doesn't have the functions you'd like > to require (e.g. fit, predict)? > You just define your own abstract types and generic functions and implement generic functionality in terms of those generic functions. There's no magic and it's all just user-level code. Is it the lack of multiple inheritance that's throwing you? Lack of formal >> specifications for protocols? The fact that generic functions live outside >> of types? >> > > Nope; those all seem like thoughtful, reasonable design decisions : ) > > After all this is sorted out, I'd be happy to distill this into a > subsection for the Julia "Types" documentation about conventions for > programming with protocols, if you think it belongs there. > For what it's worth, I do think there is need for multiple inheritance and formal protocols – we just haven't added those features and it's unclear what they should look like. The fact that generic functions live outside of types is a very good thing, however, and should not change (although #1974<https://github.com/JuliaLang/julia/issues/1974>would allow a more traditional o.o.-like style as well).
