Haven’t had time to read through this in depth, but is your concern that abstract types can’t contain fields? That is likely to get fixed at some point in the future.
— John On Dec 28, 2013, at 9:31 AM, andrew cooke <and...@acooke.org> wrote: > thanks. i've done almost exactly the same thing with the "Nothing" type at > https://github.com/andrewcooke/BlockCipherSelfStudy.jl/blob/master/src/GA.jl > > i don't think my problem is specific to GA. the problem is how to add extra > state to an api. > > in traditional OO you can use inheritance to create a new class with the > extra state. > > in julia you cannot. nor can you add it inside closures because you can't > (as far as i can tell) extend methods in another module with a closure. > > so instead you have to spot ahead of time that a user might want to add extra > state and provide an additional parameterized field (the "context" in my code > linked to above) where the user can store arbitrary information. > > which seems ugly and prone to errors (what if you miss somewhere)? > > so i still hope there's a better solution. > > cheers, andrew > > On Saturday, 28 December 2013 04:50:11 UTC-3, Toivo Henningsson wrote: > I don't have enough background in genetic algorithms to understand what you > are trying to accomplish, but I think that to answer the question of how to > write code so that it can be generally extended by users, the first thing to > ask is what the interface to the code that you want to write really is (in > abstract terms). Then, one can start to model it with types, generic > functions, inheritance, etc. > > Also, to create a generic function without actually providing any > implementations, I've lately been using things like > > f(::None) = nothing > > which seems to work fine. > >