On Monday, April 7, 2014 8:51:20 PM UTC-7, Stefan Karpinski wrote:
>
> A couple of examples of informal protocols that are used all the time in 
> Julia and allow user defined types to easily hook into predefined generic 
> behaviors are the start/done/next protocol for iteration and the order and 
> sort! protocols ordering and sorting things. The ModInt 
> example<https://github.com/JuliaLang/julia/blob/master/examples/modint.jl>shows
>  that if you just define addition and multiplication for a new 
> user-defined numeric type, you can immediately construct matrices of that 
> type and multiply them (unfortunately, this example is currently 
> broken<https://github.com/JuliaLang/julia/issues/6461>
> ).
>
> This is what I was looking for; so if I understand you correctly, you 
satisfy protocols by extending/monkey-patching Base.  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)?

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.

Reply via email to