Sounds like this: http://en.wikipedia.org/wiki/Expression_problem
On Sat, Dec 28, 2013 at 9:39 AM, andrew cooke <and...@acooke.org> wrote: > > there's a classic problem in computer science on extending apis with both > functions and state, and i remember a julia talk or paper saying that > multiple dispatch solved this nicely. > > so i think reading that might help, but i can't remember what it's called > (it the ... problem and i think there was a haskell paper by walder on it... > > andrew > > > On Saturday, 28 December 2013 11:31:07 UTC-3, andrew cooke 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. >>> >>> >>>